Skip to content

Instantly share code, notes, and snippets.

@cannap
Created September 18, 2016 00:40
Show Gist options
  • Save cannap/24cca0ebf0ce8b54fb9ea5efa4b1a586 to your computer and use it in GitHub Desktop.
Save cannap/24cca0ebf0ce8b54fb9ea5efa4b1a586 to your computer and use it in GitHub Desktop.
#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