Stay in effect after release of a button. Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
zed6250jb
Posts: 54
Joined: 20 Apr 2024, 18:25
Contact:

Stay in effect after release of a button.

26 Apr 2024, 08:31

How do you press a hotkey and after it's release, allow the function to remain in effect? I've already tried a few different ways and nothing works. I've searched documentation and other websites and found no example to this specific problem.

For example:

Code: Select all

Ins:: {
toggle := !toggle
 KeyWait 'n'
 If A_PriorKey = 'n'
  SendText 'N'
}

#HotIf toggle ? GetKeyState('Ins', 'P')
b::SendText 'n' ; perform the alternative action.
else
b::SendText 'b' ; perform the default action.
#HotIf
User avatar
mikeyww
Posts: 27146
Joined: 09 Sep 2014, 18:38

Re: Stay in effect after release of a button.  Topic is solved

26 Apr 2024, 08:51

Variables are local to functions by default. To define or change a global variable within a function, declare the variable as global within the function. Else does not apply to directives.

Code: Select all

#Requires AutoHotkey v2.0
toggle := False

Ins:: {
 Global toggle := !toggle
 SoundBeep 1000 + 500 * toggle
}

#HotIf toggle
b::n
#HotIf
zed6250jb
Posts: 54
Joined: 20 Apr 2024, 18:25
Contact:

Re: Stay in effect after release of a button.

26 Apr 2024, 11:42

"Variables are local to functions by default. To define or change a global variable within a function, declare the variable as global within the function. Else does not apply to directives."
Ah yes, I see that now. I apologize I'm not very code savvy. Looking in the search of the documentation, I couldn't find an example specific to my scenario. Thanks again!

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Draken, Henkf and 36 guests