Help with GUI Created and Destroyed in Same Thread

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
poetofpiano
Posts: 61
Joined: 25 Jan 2016, 14:26

Help with GUI Created and Destroyed in Same Thread

17 Feb 2018, 20:27

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!
poetofpiano
Posts: 61
Joined: 25 Jan 2016, 14:26

Re: Help with GUI Created and Destroyed in Same Thread

18 Feb 2018, 20:57

I figured out the reason: in the first script that had the ^u hotkey, I had SetTitleMatchMode set to 1, while in the second script that was using xbutton2 & lalt to send ^u, I had SetTitleMatchModeset to Regex. However, I still don't understand why this would cause a malfunction. Does anyone know why the script below would succeed in winactivating when placed in a script using SetTitleMatchMode, 1 but not in a script using SetTitleMatchMode, RegEx?

Code: Select all

xbutton2 & lalt:: ; works if you change titlematchmode to 1 or 2
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

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: SimmoF and 243 guests