Deactivate autorepeat of a key

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
braunbaer
Posts: 478
Joined: 22 Feb 2016, 10:49

Deactivate autorepeat of a key

25 Jul 2021, 11:52

When I hold a key for a while, windows starts autorepeating. Is there an easy way to temporarily turn that behaviour off for a specific key?
User avatar
mikeyww
Posts: 26869
Joined: 09 Sep 2014, 18:38

Re: Deactivate autorepeat of a key

25 Jul 2021, 12:08

Code: Select all

Loop, Parse, % "ef" ; Block repetitions of these characters
 Hotkey, $%A_LoopField%, Wait
Gosub, F3
F3::
block := !block
SoundBeep, 1500 - 500 * block
Return
Wait:
Send % hk := StrReplace(A_ThisHotkey, "$")
KeyWait, %hk%
Return
#If block
braunbaer
Posts: 478
Joined: 22 Feb 2016, 10:49

Re: Deactivate autorepeat of a key

25 Jul 2021, 13:51

Thank you! I don't really understand what you are doing with this script.

The F3 subroutine is executed twice (the first time through gosub, the second time by falling through), meaning that on is first set to true and then immediately to false, with the only effect that whatever hotkeys follow this part of the script will not be executed, unless the variable on is set true somewhere else or another #if follows...

Another problem with your solution is that the hotkey thread is blocked until the key is released. Looks like I'll have to program it with boolean variables manually.
User avatar
mikeyww
Posts: 26869
Joined: 09 Sep 2014, 18:38

Re: Deactivate autorepeat of a key

25 Jul 2021, 13:57

Wrong both times.

There is an implicit Return before the first hotkey. Nothing is blocked.

The best way to see this in action is to try the script.
After the script has been loaded, it begins executing at the top line, continuing until a Return, Exit, hotkey/hotstring label, or the physical end of the script is encountered (whichever comes first). This top portion of the script is referred to as the auto-execute section. Note: While the script's first hotkey/hotstring label has the same effect as return, other hotkeys and labels do not.
To start unblocked:

Code: Select all

Loop, Parse, % "ef" ; Block repetitions of these characters
 Hotkey, $%A_LoopField%, Wait
; Gosub, F3
F3::
block := !block
SoundBeep, 1500 - 500 * block
Return
Wait:
Send % hk := StrReplace(A_ThisHotkey, "$")
KeyWait, %hk%
Return
#If block
#IfWin: the bottommost occurrence applies to newly created hotkeys unless "Hotkey IfWin" has executed since the script started.
braunbaer
Posts: 478
Joined: 22 Feb 2016, 10:49

Re: Deactivate autorepeat of a key

25 Jul 2021, 17:15

Well, that's a lot of tricks in a short script :)
Now I understand what you're doing.

Thank you
User avatar
mikeyww
Posts: 26869
Joined: 09 Sep 2014, 18:38

Re: Deactivate autorepeat of a key

25 Jul 2021, 17:21

You are welcome. A similar way in case easier:

Code: Select all

F3::
block := !block
SoundBeep, 1500 - 500 * block
Return
#If block
$e::
$f::
Send % hk := StrReplace(A_ThisHotkey, "$")
KeyWait, %hk%
Return
#If

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 172 guests