Disable Auto-Repeat?

Propose new features and changes
User avatar
Coiler
Posts: 114
Joined: 29 Nov 2020, 09:06

Disable Auto-Repeat?

Post by Coiler » 26 Dec 2020, 12:19

I'm not sure if this is possible, or how difficult it would be to implement, but how about a configuration setting (#DisableAutoRepeat) that prevents hot keys from executing outside of physical events?

Essentially, it would prevent the hotkey from being called repeatedly while it is physically held down.

So the script would get a down event for down, then an up event for up, and nothing in between.

A special keyword that controlled this behavior per-key would be another great feature:

Code: Select all

LControl Press:: MsgBox( "Left control just went down. This won't show again until it is released and pressed again." )
It would be fine if the features only worked with the keyboard hook.

Thanks again for such a great utility!
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Disable Auto-Repeat?

Post by Helgef » 09 Jan 2021, 09:53

User avatar
Coiler
Posts: 114
Joined: 29 Nov 2020, 09:06

Re: Disable Auto-Repeat?

Post by Coiler » 16 Mar 2021, 16:11

The easiest/cleanest method I've discovered is to just keep AHK threads locked until the key is released. That usually means using KeyWait() or a tightly closed loop that keeps checking the key state.

In my own somewhat complex script, I create a "thread tag" for each unique physical key that is registered. One single tag exists for each primary key, and multiple actions that deploy from the same key share the same tag. So actions just use if !tag.start() return and tag.stop() when their hotkeys are launched. The tags only allow one execution at a time, and internally wait for the key release in their stop function.

Although my tag system blocks auto-repeat, I actually wrote it to ensure that only one hotkey executes for each key sequence. If two hotkeys share similar testing conditions, they will both launch, rather than just the one that has more complex/difficult conditions. For example, if two hotkeys are binded to the same key, and hotkey A has conditions ( 1 & 2 ) while hotkey B has conditions ( 1 & 2 & 3 ), then in all cases where B can execute, A will also execute. So you just make sure A B is checked first, then A will be blocked by the thread tag. EDIT: Got those two backwards in that last sentence. I meant that you just have to make sure the most complex conditions are checked first.

It would be great if there were some way to limit hotkey callbacks to 1 per physical press, internally. I have not done any research or checked the source code, but I'm assuming there is a much deeper point in the key event, and a much cleaner manner in which AHK could essentially ask itself "Have I already sent a down event for this key since the last up event?"
Post Reply

Return to “Wish List”