Switch to Last Active Window of Each Application?

Get help with using AutoHotkey and its commands and hotkeys
wred
Posts: 1
Joined: 13 Jun 2019, 14:13

Switch to Last Active Window of Each Application?

23 Jun 2019, 15:05

Hi everyone, so I hope this hasn't already been covered but I was looking for a script that I could use to switch to the last active window of each application. So, for instance, if I have two Chrome windows, two Word documents and two file explorer windows open, I want to be able to press a hotkey to cycle through three windows: the most recently active Chrome window, the most recently active Word window, and the most recently active file explorer window. I found this thread, which I initially thought would do what I wanted, but it only toggles between 2 windows/apps: https://autohotkey.com/board/topic/116740-switch-between-one-window-of-each-different-applications/

Here is the code:

Code: Select all

Unique_Alt_Tab_Windows()
{
  alt_tab_list := Array()
  class_list := ""
  WinGet, window_list, List
  Loop % window_list
  {
    this_hwnd := window_list%A_Index%

    
    WinGet, this_style, Style, ahk_id %this_hwnd%
    if (this_style & 0x10000000) && (this_style & 0x10000) ; 0x10000000 is WS_VISIBLE. 0x10000 is WS_MAXIMIZEBOX
    {
      WinGetTitle, this_title, ahk_id %this_hwnd%
      if((this_title = "") || (this_title = "Start"))
        continue
      else
      {
        WinGetClass, this_class, ahk_id %this_hwnd%
        if !InStr(class_list, this_class)
        {
          alt_tab_list.Insert(this_hwnd)
          class_list .= this_class . "|"
        }
      }
    }
  }
  return alt_tab_list
}

Code: Select all

#IfWinActive
!Tab::

alt_tab_list := Unique_Alt_Tab_Windows()
initial_window := alt_tab_list[2]
WinActivate, ahk_id %initial_window%
active_index := 2
Loop
{
  
  KeyWait, Tab, DT0.5
  if !ErrorLevel
  {
    active_index++
    this_window := alt_tab_list[active_index]
    WinActivate, ahk_id %this_window%
  }
  if(active_index >= alt_tab_list.MaxIndex())
  {
    alt_tab_list := Unique_Alt_Tab_Windows()
    active_index := 1
  }
} until (!GetKeyState("Alt", "P"))
return

Return to “Ask For Help”

Who is online

Users browsing this forum: adrian88888888, aifritz, Albireo, Bing [Bot], HiSoKa, vsub, Yakshongas and 335 guests