This is my autohotkey function, so that Windows gets the same functionality as OSX for cycling through instances of the same app (e.g. multiple firefox instances). Pass 0 or 1 to cycle all apps, or apps on the same desktop.
!`::CycleCurrentApplication(0)
!+`::CycleCurrentApplication(1)
WhichMonitorAppIsOn(winId) {
WinGetPos, cX, cY, cW, cH, ahk_id %winId%
xMid := cX + (cW / 2)
yMid := cY + (cH / 2)
SysGet, nMons, MonitorCount
Loop, % nMons
{
; MsgBox %A_Index%
SysGet, tmp, Monitor, %A_Index%
withinWidth := (xMid > tmpLeft) && (xMid < tmpRight)
; MsgBox % tmpLeft . " -> " . tmpRight . "`t" . xMid
if (withinWidth == 1)
return %A_Index%
}
}
CycleCurrentApplication(same_desktop_only) {
WinGet, curID, ID, A
curMon := WhichMonitorAppIsOn(curID)
WinGetClass, ActiveClass, A
WinGet, WinClassCount, Count, ahk_class %ActiveClass%
IF WinClassCount = 1
Return
Else
WinGet, List, List, % "ahk_class " ActiveClass
Loop, % List
{
index := List - A_Index + 1
WinGet, State, MinMax, % "ahk_id " List%index%
WinGet, nextID, ID, % "ahk_id " List%index%
nextMon := WhichMonitorAppIsOn(nextID)
if (same_desktop_only > 0 && (curMon != nextMon))
continue
if (State != -1) ; if window not minimised
{
WinID := List%index%
break
}
}
WinActivate, % "ahk_id " WinID
}