5
votes

Is there a way to unpress all pressed keys with AHK?

By pressed, I mean Send {something down}

and by unpress I mean Send {something UP}

2
Just curious - why on Earth do you want to do that?Brad Peabody
I got a script that presses keys. When I end the script, the keys are still pressed and that messes up with the rest of my work.RainingChain
Yes, it is possible. You already know the right command: Send {KEY up}. Where are you stuck?MCL

2 Answers

6
votes

You're in the right direction. All you would need to do is to create a list of keys to check, then add an if statement (if needed at all) to unpress the keys if pressed.

KeyList := "Shift|a|b|c|d|e|f|g|h|i|j" ; and so on

Loop, Parse, KeyList, |
{
    If GetKeystate(A_Loopfield, "P")
        Send % "{" A_Loopfield " Up}"
}
0
votes

Just in case when you say "messes up with the rest of my work." do you mean triggers other hotkeys? Because if so you can disable Hotkeys:

Hotkey, ^c, Off ; Disables the Ctrl + C hotkey
Hotkey, ^c, On ; Enables the Ctrl + C hotkey
Hotkey, ^c, Toggle ; Flips Ctrl + C to other state in this case to Off
Hotkey, ^c, Toggle ; Flips Ctrl + C to other state in this case to On

Hopefully that is helpful. You can find full documentation here.