Created
September 18, 2016 00:40
-
-
Save cannap/24cca0ebf0ce8b54fb9ea5efa4b1a586 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Persistent | |
SetTimer, WinChange, 2000 | |
Switched := -1 | |
return | |
WinChange: | |
WinGetTitle, title, A | |
GetMonitor(hwnd := 0) { | |
; If no hwnd is provided, use the Active Window | |
if (hwnd) | |
WinGetPos, winX, winY, winW, winH, ahk_id %hwnd% | |
else | |
WinGetActiveStats, winTitle, winW, winH, winX, winY | |
SysGet, numDisplays, MonitorCount | |
SysGet, idxPrimary, MonitorPrimary | |
Loop %numDisplays% | |
{ | |
SysGet, mon, MonitorWorkArea, %a_index% | |
; Left may be skewed on Monitors past 1 | |
if (a_index > 1) | |
monLeft -= 10 | |
; Right overlaps Left on Monitors past 1 | |
else if (numDisplays > 1) | |
monRight -= 10 | |
; Tracked based on X. Cannot properly sense on Windows "between" monitors | |
if (winX >= monLeft && winX < monRight) | |
return %a_index% | |
} | |
; Return Primary Monitor if can't sense | |
return idxPrimary | |
} | |
currentMonitor := GetMonitor(title) | |
if(currentMonitor = 1) { | |
if(Switched = 0){ | |
Send {ctrl Up}{F1 Up} | |
} | |
Switched := 1 | |
}else { | |
if(Switched = 1){ | |
Send {ctrl Up}{F2 Up} | |
} | |
Switched := 0 | |
} | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment