Bind commands to key-up and key-down in AutoHotkey
6,263
Solution 1
You could compile your .ahk scripts as .exe. Then have
Pause::C:\fun1.exe
Pause Up::C:\fun2.exe
More info on .akh to .exe: autohotkey- ahk2exe
Solution 2
You can accomplish the desired functionality with this code:
pause::
fun1()
keyWait, pause
fun2()
return
If you are dealing with subroutines instead, use this:
pause::
gosub, sub1
keyWait, pause
gosub, sub2
return
Related videos on Youtube
![Malabarba](https://i.stack.imgur.com/K6sjh.jpg?s=256&g=1)
Author by
Malabarba
Updated on September 17, 2022Comments
-
Malabarba almost 2 years
I have written two functions in an AutoHotkey script:
fun1()
andfun2()
. I now need to bindfun1()
to when Pause is pressed down, and bindfun2()
to when Pause is released.As an example, I would press and hold Pause to hide all windows, and release Pause to restore all windows. (This example is not my actual objetive).
How can I do that in AutoHotkey?
-
Malabarba over 13 yearsActually, compiling them is unnecessary. I already defined them as functions. My question regarded specifically to the key up/down syntax. I wasn't finding it in the manual, so I asked here. Eventually I found a couple examples online, and it's exactly what you said except there's a blank space between "pause" and "up/down".
-
nixda almost 10 yearsNo need to add
Down
since its the default trigger. OnlyUp
must be specified -
vanessa over 3 yearsThis is right answer. Because it handles long press without sending mulltiple "keyDown" events.
-
vanessa over 3 yearsWrong. Long press of Pause will send multiple "keyDown" evens, launching
C:\fun1.exe
multiple times.