Hi everyone! I have been using the following hotkey for a long time to display a GUI that allows me to activate any of the open windows of the currently active application:
Code: Select all
^u::
WinGet, pn, processname, A
WinGet, l, list, ahk_exe %pn%
Loop % l
{
WinGetTitle, t, % "ahk_id " l%A_Index%
If t ; add to the list if there is a title to the window it identified
Gui, 3:Add, Button, gactivate, %t%
}
Gui, 3:Show, x925 y473
return
activate:
WinActivate, % A_GuiControl
Gui, 3:Destroy
return
My preferred way to bring up this GUI is actually not by hitting
^u, but by pressing
xbutton2 & lalt to call the
^u hotkey that is in a different script, hover the mouse over my desired window listed in the GUI, and then release
xbutton2 to activate the desired window and close the GUI:
Code: Select all
xbutton2 & lalt::
mousegetpos, xpos, ypos
send ^u ; hotkey for window switching in different script
mousemove, 970, 585 ; center of GUI window
keywait, xbutton2
click
mousemove, %xpos%, %ypos%
}
return
Like I said, the only thing is that this
xbutton2 & lalt hotkey for some reason must be placed in an entirely different Autohotkey script or else it doesn't work for me. If, for example, I try to combine all the actions into one hotkey, as below, it either doesn't function smoothly or doesn't function at all when I release
xbutton2 over the button of the window that I want to activate:
Code: Select all
xbutton2 & lalt::
WinGet, pn, processname, A
WinGet, l, list, ahk_exe %pn%
Loop % l
{
WinGetTitle, t, % "ahk_id " l%A_Index%
If t ; add to the list if there is a title to the window it identified
Gui, 3:Add, Button, gactivate, %t%
}
Gui, 3:Show, x925 y473
mousegetpos, xpos, ypos
mousemove, 970, 585 ; center of GUI window
keywait, xbutton2
click
mousemove, %xpos%, %ypos%
return
activate:
WinActivate, % A_GuiControl
Gui, 3:Destroy
return
If you compare these two setups, I think you will notice that the first one operates 100% of the time and the mouse movements are instant, while the second setup often doesn't work or is very slow, like I said. Can anyone shed light on what I'm doing wrong? Thank you so much in advance!