Variable results for single hotkey Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
WeThotUWasAToad
Posts: 312
Joined: 19 Nov 2013, 08:44

Variable results for single hotkey

15 Apr 2021, 11:04

Hello,

How do you construct a script so that a given hotkey will result in variable processes depending on the currently active window?

Below is a basic template I wrote for doing the above. It follows the assumption that it will work down looking for an "IF" criteria to be met and when it is, execute the corresponding Process, at which point the script will end.

Is that correct or will the script continue looking for subsequent IFs? If yes, then how can I modify the script so that it will stop once an IF criteria is met?

Code: Select all

F1::
SetTitleMatchMode, 2
IfWinActive, Screen1
	{
	GoSub, Process1
	}
IfWinActive, Screen2
	{
	GoSub, Process2
	}
IfWinActive, Screen3
	{
	GoSub, Process3
	}
Return
Thanks
A ------------------------------ [A LOT OF SPACE] ------------------------------ LOT

"ALOT" is not a word. It never has been a word and it never will be a word.
"A LOT" is 2 words. Remember it as though there's [A LOT OF SPACE] between them.
User avatar
mikeyww
Posts: 26931
Joined: 09 Sep 2014, 18:38

Re: Variable results for single hotkey  Topic is solved

15 Apr 2021, 11:29

Your fundamental assumption contrasts with how computer programs generally work (though AHK has some exceptions, too). The code runs, line by line, until a command tells it to stop, an error occurs, or the script exits. To end the routine, you can insert additional Return at any point, such as inside any of the braces.

Alternatives are Else, or using an #IfWinActive directive to separate the routines.

Switch is another way to accomplish what you have described: a maximum of one Switch branch will be taken. See the documentation.
WeThotUWasAToad
Posts: 312
Joined: 19 Nov 2013, 08:44

Re: Variable results for single hotkey

15 Apr 2021, 18:21

Thanks for the comments Mike.

By simply adding the word Else to the beginning of the IF lines, I can get the behavior I want (ie if it finds the defined criteria then it executes the corresponding action and the script stops. Otherwise, the script continues.)

Thanks again
A ------------------------------ [A LOT OF SPACE] ------------------------------ LOT

"ALOT" is not a word. It never has been a word and it never will be a word.
"A LOT" is 2 words. Remember it as though there's [A LOT OF SPACE] between them.
User avatar
mikeyww
Posts: 26931
Joined: 09 Sep 2014, 18:38

Re: Variable results for single hotkey

15 Apr 2021, 19:15

Good to hear. Alotof luck to you.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bobak, mapcarter and 292 guests