How To Stop Auto-Repeat Behavior Of Hotkey? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Mulsiphix
Posts: 148
Joined: 20 Nov 2015, 17:56

How To Stop Auto-Repeat Behavior Of Hotkey?

Post by Mulsiphix » 27 Jan 2022, 12:13

I have a double-press script. I often hold down the LShift hotkey that activates it. When held down, the script often executes repeatedly. I assume because the LShift key is auto-repeated by Windows. Is there a way to halt this auto-repeat behavior, while still allowing the script to detect double presses? I found GetKeyState, KeyWait, If/Else, and Loop in the AHK Documentation, but have been unable to come up with any design that works for this specific situation.

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: How To Stop Auto-Repeat Behavior Of Hotkey?  Topic is solved

Post by mikeyww » 27 Jan 2022, 12:20

Feel free to post your script for feedback about it.

Code: Select all

LShift::
Click, 2
SoundBeep, 1500
KeyWait, LShift
SoundBeep, 1000
Return

Mulsiphix
Posts: 148
Joined: 20 Nov 2015, 17:56

Re: How To Stop Auto-Repeat Behavior Of Hotkey?

Post by Mulsiphix » 27 Jan 2022, 13:11

Thank you mikeyww, I might do that. Regarding the script you posted, when I hold down the LShift key, I hear those beeps repeating for as long as I hold LShift down. Is there a way to stop it from repeating? What I am after is:

1. Press LShift down and do not physically release it. The script executes only once.
2. I continue to hold LShift down for 30 seconds, but script does not fire a second or more times.
3. Finally, I release the LShift key. Then physically press it a second time. The script executes for a second time.

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: How To Stop Auto-Repeat Behavior Of Hotkey?

Post by mikeyww » 27 Jan 2022, 13:35

That's surprising because the hook is installed at my end, but you could add #InstallKeybdHook at the top. It works here. Use this exact script with no other code, and no other scripts running at the same time. Test in Notepad.

Mulsiphix
Posts: 148
Joined: 20 Nov 2015, 17:56

Re: How To Stop Auto-Repeat Behavior Of Hotkey?

Post by Mulsiphix » 27 Jan 2022, 19:22

I apologize. Your script does work perfectly. I had the AHK script I am working on running in the background, which utilizes LShift. So I changed the hotkey in your script from LShift to a. But I failed to update the KeyWait command. I closed all other AHK scripts like you suggested and now your script works flawlessly. And without needing to specify #InstallKeybdHook. I am sorry about that. Thank you so much for your help :dance:

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: How To Stop Auto-Repeat Behavior Of Hotkey?

Post by mikeyww » 27 Jan 2022, 19:30

Good to hear. Thank you for the report. Have fun with it.

Post Reply

Return to “Ask for Help (v1)”