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
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