faster keystroke repeat delay?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
tatagi
Posts: 181
Joined: 23 Aug 2018, 11:17

faster keystroke repeat delay?

16 Sep 2020, 23:42

Have a look at this code:

Code: Select all

capslock & k::send {wheeldown}
return
Can't be simpler. It is just replacement for wheeldown by using keyboard.

So when I hold this hotkey, it keeps scrolling until I release the k. Quite convenient.

And I decided to further upgrade this for much better browsing experience.
what I want done is, when I start pressing k, I want it to start sending wheeldown command right away(just like I use the physical mouse wheel)

As you guys know, there is keyboard configuration in control panel on Windows where you can set the repeat delay(it defines the pause between pressing a key and when it starts repeating while you are holding that key. Don't misunderstand with repeat speed) using the slide from long to short with four steps available.

I am happy with its default settings(set 3) which suits my typing habit best.
so I want to leave it alone, and just change that delay only in special circumstance where I am using the above hotkeys.

To sum up, when I press capslock and then k, I want the repeat delay to be almost zero(so it sends wheeldown instantly, or better if I can set the time amount myself) while normal typing is not affected(window's system setting applies when just pressing k in typing operation including all other keys of course).


Hope you guys understand what I am trying to achieve(Many I met had miunderstood between repeat delay and repeat rate).

thx!
User avatar
Jim Dunn
Posts: 478
Joined: 01 Sep 2020, 20:21
Location: NSW

Re: faster keystroke repeat delay?

17 Sep 2020, 00:51

Something like

Code: Select all

CapsLock & k::
While GetKeyState("k", "P") {
	Send, {WheelDown 1}
	Sleep, 50
}
Return

CapsLock & i::
While GetKeyState("i", "P") {
	Send, {WheelUp 1}
	Sleep, 50
}
Return
Shouldn't have that initial repeat delay - but, because it's kinda "bypassing" the OS repeat settings you'd probably need to play with the Sleep periods and # of WheelDowns each loop sends in order to come up with exactly what you want.
tatagi
Posts: 181
Joined: 23 Aug 2018, 11:17

Re: faster keystroke repeat delay?

17 Sep 2020, 01:21

Jim Dunn wrote:
17 Sep 2020, 00:51
Something like

Code: Select all

CapsLock & k::
While GetKeyState("k", "P") {
	Send, {WheelDown 1}
	Sleep, 50
}
Return

CapsLock & i::
While GetKeyState("i", "P") {
	Send, {WheelUp 1}
	Sleep, 50
}
Return
Shouldn't have that initial repeat delay - but, because it's kinda "bypassing" the OS repeat settings you'd probably need to play with the Sleep periods and # of WheelDowns each loop sends in order to come up with exactly what you want.


Thank you so much for the reply, it works quite well. But I need an update here.
Is it also possible to set the amount of time of delay for the repeat? Being instantly responsive is excellent, but the problem is I can't get the wheeldown just once(one notch) unless I am a superhuman fast enough to outrun that darn "P" parameter lols. my fault I forgot to think of it.
User avatar
Jim Dunn
Posts: 478
Joined: 01 Sep 2020, 20:21
Location: NSW

Re: faster keystroke repeat delay?

17 Sep 2020, 01:27

The "P" parameter to GetKeyState just means "is pressed". You can't adjust anything with that.

You can increase the Sleep, 50 - that will increase the time before the keystate is checked again and another wheeldown is sent. (slower "repeat rate" if you like)

You can increase the {WheelDown 1} to {WheelDown 2} etc... and it will send more than one WheelDown event per loop.

If you want to change the number of lines each WheelDown event moves, I think you need to do that in windows settings - and that will affect the wheel behaviour when you use the actual mouse too.
Mine is set to 3 lines - and that must be the default, because I've never altered it.

You could also add an additional Sleep, like this, before the repeat loop, but after one initial WheelDown is sent

Code: Select all

CapsLock & k::
Send, {WheelDown 1}
Sleep 650 ; initial delay before starting to repeat
While GetKeyState("k", "P") {
	Send, {WheelDown 1}
	Sleep, 50 ; repeat delay - increase this to reduce the repeat 'rate'
}
Return
That will emulate the initial delay we were trying to avoid - but now it will be adjustable.
Last edited by Jim Dunn on 17 Sep 2020, 01:50, edited 1 time in total.
tatagi
Posts: 181
Joined: 23 Aug 2018, 11:17

Re: faster keystroke repeat delay?

17 Sep 2020, 01:48

Jim Dunn wrote:
17 Sep 2020, 01:27
The "P" parameter to GetKeyState just means "is pressed". You can't adjust anything with that.

You can increase the Sleep, 50 - that will increase the time before the keystate is checked again and another wheeldown is sent. (slower "repeat rate" if you like)

You can increase the {WheelDown 1} to {WheelDown 2} etc... and it will send more than one WheelDown event per loop.

If you want to change the number of lines each WheelDown event moves, I think you need to do that in windows settings - and that will affect the wheel behaviour when you use the actual mouse too.
Mine is set to 3 lines - and that must be the default, because I've never altered it.
Hello. that is good alternative, the problem is increasing the sleep lets me wheelscroll one notch, but at the same time will slow the repeat rate down as you mentioned and it would make the screen look like it freezes between each scrolls and not so smooth.

two factor into consideration:

1. you should be able to have time to press and release hotkey before the repeat delay is reached. (for one notch of scroll to work)
2. sleep should be short enough to guarantee the butter smooth consecutive scrolling. (when navigating through long articles that requires skim reading)

thx!
User avatar
Jim Dunn
Posts: 478
Joined: 01 Sep 2020, 20:21
Location: NSW

Re: faster keystroke repeat delay?

17 Sep 2020, 01:52

tatagi wrote:
17 Sep 2020, 01:48
two factor into consideration:

1. you should be able to have time to press and release hotkey before the repeat delay is reached. (for one notch of scroll to work)
2. sleep should be short enough to guarantee the butter smooth consecutive scrolling. (when navigating through long articles that requires skim reading)
That's what my revision above with the additional (adjustable), initial Sleep tries to do. ;)

This one:

Code: Select all

CapsLock & k::
Send, {WheelDown 1}
Sleep, 650 ; initial delay before starting to repeat
While GetKeyState("k", "P") {
	Send, {WheelDown 1}
	Sleep, 50 ; repeat delay - increase this to reduce the repeat 'rate' (and vice-versa)
}
Return
That will emulate the initial delay we were originally trying to avoid - but now it will be adjustable for this individual hotkey.
You can try different values for the first Sleep (650) to see if you can find one you like. ;)
tatagi
Posts: 181
Joined: 23 Aug 2018, 11:17

Re: faster keystroke repeat delay?

17 Sep 2020, 02:35

Jim Dunn wrote:
17 Sep 2020, 01:52
tatagi wrote:
17 Sep 2020, 01:48
two factor into consideration:

1. you should be able to have time to press and release hotkey before the repeat delay is reached. (for one notch of scroll to work)
2. sleep should be short enough to guarantee the butter smooth consecutive scrolling. (when navigating through long articles that requires skim reading)
That's what my revision above with the additional (adjustable), initial Sleep tries to do. ;)

This one:

Code: Select all

CapsLock & k::
Send, {WheelDown 1}
Sleep, 650 ; initial delay before starting to repeat
While GetKeyState("k", "P") {
	Send, {WheelDown 1}
	Sleep, 50 ; repeat delay - increase this to reduce the repeat 'rate' (and vice-versa)
}
Return
That will emulate the initial delay we were originally trying to avoid - but now it will be adjustable for this individual hotkey.
You can try different values for the first Sleep (650) to see if you can find one you like. ;)

It's getting better and better :D Thanks to adding initial sleep period, I can send one notch event, while I can still navigate fast and smooth :)

But one problem after another.. just like life always does lols

What if I need to quickly send a set of single notch? if the initial sleep is too short, it won't allow me time for the one notch scroll
and if it is too long, it will not perform exact count of a set of quick individual wheelscroll. For example, If I press capslock + k 5 times individually and initial sleep is set to 650, 2 out of 5 would be missed out. And I can't seem to find the match point that meets all these criteria and even if there is, I will always have to mind how fast/slow I should be pressing hotkey to satisfy all the requirement to get it working without flaw
User avatar
Jim Dunn
Posts: 478
Joined: 01 Sep 2020, 20:21
Location: NSW

Re: faster keystroke repeat delay?

17 Sep 2020, 02:40

I understand what you are saying - there might be a way to achieve that with SetTimer, but I'll have to give it a little thought, and I need to go out for a little while.
tatagi
Posts: 181
Joined: 23 Aug 2018, 11:17

Re: faster keystroke repeat delay?

17 Sep 2020, 02:55

Jim Dunn wrote:
17 Sep 2020, 02:40
I understand what you are saying - there might be a way to achieve that with SetTimer, but I'll have to give it a little thought, and I need to go out for a little while.
I already appreciate what you've done for me with your time and effort. I will try to figure out the rest but I would appreciate even 1000x more if you could sort out solution for this sleep dilemma!
User avatar
Jim Dunn
Posts: 478
Joined: 01 Sep 2020, 20:21
Location: NSW

Re: faster keystroke repeat delay?

17 Sep 2020, 03:26

Ok - try this:

Code: Select all

CapsLock & k::
Send, {WheelDown 1}
Sleep, 150 ; Wait, then check if key was just "tapped"
If !(GetKeyState("k", "P"))
	Return ; quit if it was just a "tap"
;ok - key was held - let's wait to see if held long enough to repeat
Sleep, 500 ; initial delay before starting to repeat
While GetKeyState("k", "P") {
	Send, {WheelDown 1}
	Sleep, 50 ; repeat delay - increase this to reduce the repeat 'rate' (and vice-versa)
}
Return
The logic now is to first check if you were just "tapping" the key before it starts deciding if you've held it long enough to start repeating.

I haven't tested it much - but it did seem to be doing what it was supposed to.

You've now got 3 configurable things:
1. How long it considers to be "just a tap"
2. How long to then wait before it's been held in long enough to start repeating
3. Repeat 'rate' if it gets as far as repeating.
tatagi
Posts: 181
Joined: 23 Aug 2018, 11:17

Re: faster keystroke repeat delay?

17 Sep 2020, 05:25

Jim Dunn wrote:
17 Sep 2020, 03:26
Ok - it's getting a bit complex now, but try this:

Code: Select all

CapsLock & k::
Send, {WheelDown 1}
Sleep 150 ; Wait, then check if key was just "tapped"
If !(GetKeyState("k", "P"))
	Return ; quit if it was just a "tap"
;ok - key was held - let's wait to see if held long enough to repeat
Sleep, 650 ; initial delay before starting to repeat
While GetKeyState("k", "P") {
	Send, {WheelDown 1}
	Sleep, 50 ; repeat delay - increase this to reduce the repeat 'rate' (and vice-versa)
}
Return
The logic now is to first check if you were just "tapping" the key before it starts deciding if you've held it long enough to start repeating.

I haven't tested it much - but it did seem to be doing what it was supposed to.

You've now got 3 configurable things:
1. How long it considers to be "just a tap"
2. How long to then wait before it's been held in long enough to start repeating
3. Repeat 'rate' if it gets as far as repeating.
hello jim, many thanks for your effort again and sorry for bad english :shifty:

I played with your code, tried to adjust the values but IMHO I am afraid that the setting "sleep" time is not foolproof solution that address the problem I reported. For example take a look at your code(I changed a value that I thought to meet my typing habit best)
CapsLock & k::
Send, {WheelDown 1}
Sleep 150 ; Wait, then check if key was just "tapped"
If !(GetKeyState("k", "P"))
Return ; quit if it was just a "tap"
;ok - key was held - let's wait to see if held long enough to repeat
Sleep,300 ; initial delay before starting to repeat
While GetKeyState("k", "P") {
Send, {WheelDown 1}
Sleep, 50 ; repeat delay - increase this to reduce the repeat 'rate' (and vice-versa)
}
Return
let's say I am holding capslock, and now I have to press k 5 times (not hold down).
if I tap each k 5 times at large intervals (k, rest 0.5 sec, k, 0.5, k, 0.5, k, 0.5, k) and at the same time with press of each k released quickly within 150ms) , it works as directed. no keypress is omitted and it prevent repeat command from happening.
but if the interval is smaller (k, 0.1, k, 0.1 etc...which I assume my fastest keystroke in a row) it still prevents the repeat but one or two keypress is omitted which is definitely the problem in terms of consistency.

and whatever value I set it to, the problem persists. it's like catching two hares that run in two direction. As you can see, this problem therefore only applies when the interval is short(meaning multiple keypress is done fast).

1. if I decrease the tap value below 0.1sec(100ms) not to omit anything, I should be extra careful to release each k within 100(it would be stressful to always care about it) not to repeat command to be sent by accident.

2. Vice versa. if I increase the tab value above 0.1sec(100ms) not to repeat accidentally, there's chance the some of the keystroke is omitted in the same manner.


I think this is the nature of sleep command :(
User avatar
Jim Dunn
Posts: 478
Joined: 01 Sep 2020, 20:21
Location: NSW

Re: faster keystroke repeat delay?

17 Sep 2020, 05:54

As I said above - there might be a way to improve it using SetTimer instead of sleeping so much. I'll keep thinking about it and if I get something I think works better I'll post it, unless someone beats me to it.
tatagi
Posts: 181
Joined: 23 Aug 2018, 11:17

Re: faster keystroke repeat delay?

17 Sep 2020, 06:19

Jim Dunn wrote:
17 Sep 2020, 05:54
As I said above - there might be a way to improve it using SetTimer instead of sleeping so much. I'll keep thinking about it and if I get something I think works better I'll post it, unless someone beats me to it.
That's so nice of you. I would ask around but autohotkey is not so popular in my country so I compeletely rely on this forum.

Wish you luck!
User avatar
Jim Dunn
Posts: 478
Joined: 01 Sep 2020, 20:21
Location: NSW

Re: faster keystroke repeat delay?

17 Sep 2020, 07:56

I will say this, though.

You said:
if I decrease the tap value below 0.1sec(100ms) not to omit anything, I should be extra careful to release each k within 100(it would be stressful to always care about it) not to repeat command to be sent by accident.
If you're holding a key down, then you're holding it down.
Regardless of what the delay setting is, if you hold it down longer then you've held it down longer.
I'm really not sure what the code would look like to determine your intention, and whether you were holding it down "by accident" or not... :)

If I do ever solve that one it will be great, because when my cat walks across my keyboard, as he does a lot, I'm sure he doesn't intend to trigger things on my computer which I probably couldn't do if I tried - and he does that a lot too, bless him... :)
tatagi
Posts: 181
Joined: 23 Aug 2018, 11:17

Re: faster keystroke repeat delay?

17 Sep 2020, 21:21

Jim Dunn wrote:
17 Sep 2020, 07:56
I will say this, though.

You said:
if I decrease the tap value below 0.1sec(100ms) not to omit anything, I should be extra careful to release each k within 100(it would be stressful to always care about it) not to repeat command to be sent by accident.
If you're holding a key down, then you're holding it down.
Regardless of what the delay setting is, if you hold it down longer then you've held it down longer.
I'm really not sure what the code would look like to determine your intention, and whether you were holding it down "by accident" or not... :)

If I do ever solve that one it will be great, because when my cat walks across my keyboard, as he does a lot, I'm sure he doesn't intend to trigger things on my computer which I probably couldn't do if I tried - and he does that a lot too, bless him... :)

Exactly. It wouldn't know the difference until AHK begins to support artificial intelligence and deep learning :roll:

Sometimes it frustrates me that what seems to be easy turns out to be so complicated.
I would not give up on this for now, but I gotta prepare for the worst and get used to the new code not to make mistakes "By accident"

your cat might need your attention and hug, so give it what he want! 🐱

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: garry and 150 guests