MarvinJWendt
MarvinJWendt

Reputation: 2694

Run hotkey if no window is active

My problem is that I want to create a shortcut with AHK. The shortcut should do different stuff when I have different windows open.

This is my current code:

#SingleInstance, force
#IfWinActive, ahk_exe explorer.exe

CapsLock & P::
    Send, !FR
return

#IfWinActive 

CapsLock & P::
    Run, powershell, , , PID
    WinWait, ahk_pid %PID%
    WinActivate, ahk_pid %PID%
    Send, CD /{Enter}cls{Enter}
return

It works, except when no window is active.

How can I make it check if no window is active (Desktop focused as an example)?

Upvotes: 1

Views: 652

Answers (1)

Oleg
Oleg

Reputation: 6324

When the desktop is focused explorer.exe is the active window(it's a windows thing). So that's a problem.

If the other shortcut needs to run when the file explorer is active it can be differentiated from the explorer that is active when the desktop is focused by it's title(when the desktop is focused the title is blank).

#IfWinActive File Explorer ahk_exe explorer.exe

Upvotes: 2

Related Questions