Skip to content

Instantly share code, notes, and snippets.

@kosugi
Created October 7, 2020 09:49
Show Gist options
  • Select an option

  • Save kosugi/62ce68e74a9ac1884ccccbc3611ae30a to your computer and use it in GitHub Desktop.

Select an option

Save kosugi/62ce68e74a9ac1884ccccbc3611ae30a to your computer and use it in GitHub Desktop.
;;
;; macOS の「次のウィンドウを操作対象にする」を実現するための AutoHotkey Script
;;
;; active window が属する process の window 群の中で,
;; active window の window handle が次に大きい (かつ UI を持つ) window を focus する.
;;
;; is_asc が false の場合は「次に小さい」 window を対象とする.
;;
;; TODO: 「UI を持つ」判定に window style を用いているが確証が無い
;;
next_app_window(is_asc)
{
WinGet, active_hwnd, ID, A
WinGet, active_pid, PID, A
WinGet, ids, list, ahk_pid %active_pid%
s := ""
Loop % ids
{
hwnd := ids%a_index%
WinGet, style, style, ahk_id %hwnd%
Transform, r, BitAnd, %style%, 0x80080000 ; WS_POPUP | WS_SYSMENU
If (r == 0x00080000)
{
If (s != "")
{
s .= ","
}
s .= hwnd
}
}
If (is_asc)
{
Sort, s, N D,
}
else
{
Sort, s, N R D,
}
hwnds := StrSplit(s, ",")
hwnds[hwnds.length() + 1] := hwnds[1]
For i, hwnd in hwnds
{
If (active_hwnd == hwnd)
{
WinActivate, % "ahk_id " hwnds[i + 1]
Break
}
}
Return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment