wildeyes
wildeyes

Reputation: 7517

Autohotkey: Activate foremost of X monitor

How do I activate the foremost window in a given monitor? suppose I have two monitors, one with an editor, and one with different apps, such as chrome and slack. I want to bind a key that will activate the foremost window in monitor two, be it slack or chrome, and one for the editor, for easy manuvering.

Upvotes: 0

Views: 100

Answers (1)

Relax
Relax

Reputation: 10568

The foremost window in a given monitor is the currently active window or (if the currently active window is on the other monitor) the last active window of this monitor.

; activate the editor:
F1::
WinActivate, ahk_exe notepad.exe    ; replace notepad with the ahk_exe of the editor
return

; activate the last active window in the right monitor:
F2::
WinGetPos, X,,,, A
If (X > 1920)   ; replace 1920 with the width of the left monitor
    return  ; do nothing
; otherwise:
WinGet, id, list
Loop, %id%
{
    this_ID := id%A_Index%
    WinGet, exStyle, exStyle, ahk_id %this_ID%
    If !(exStyle & 0x100)
        continue
    WinGetTitle, title, ahk_id %this_ID%
    If (title = "")
        continue
    WinGetPos, X,,,, ahk_id %this_ID%
    If (X > 1920)   ; replace 1920 with the width of the left monitor
    {
        WinActivate, ahk_id %this_ID%       
            break
    }
}
return

Upvotes: 1

Related Questions