key accidentally released while pressing hotkey, how to prevent this?

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

key accidentally released while pressing hotkey, how to prevent this?

18 Sep 2020, 20:02

this is my example code.

capslock & a:: send {wheeldown}


and I used this for weeks now. everything works fine and I am happy it replaces 30 percent of my mouse usage.
but here's where the problem starts.
I use it quite frequently that sometimes I unexpectedly cause the hotkey to cease while in the middle of use.

the way hotkey sends the wheeldown event is like this as you know:
capslock pressed --> a pressed --> hotkey fires --> a released --> hotkey stops --> capslock released
or other people would release both keys at the same time.

the problem is, some of the time and by mistake, I release capslock key first while I still press "a" and if "a" is kept pressed long enough, it sends literal {a} key which is definitely not I want.

any solution to work this out? well for example, to make hotkey go on until "a" is released(but except for when a is used alone as literal character)
User avatar
mikeyww
Posts: 26945
Joined: 09 Sep 2014, 18:38

Re: key accidentally released while pressing hotkey, how to prevent this?

19 Sep 2020, 09:02

It seems that when a is pressed, you want the following to happen.

1. If CAPSLOCK was pressed recently, do nothing.

2. If CAPSLOCK was not pressed recently, send a.

You could write a script for a that would do that. You can define "recently" according to when CAPSLOCK was last pressed. A_TickCount can be used to compute time differences. Store a value when you want, and then subtract it from the current value.

An alternative approach could simply be to set a short timer when CAPSLOCK is released. Block input until the timer expires.
tatagi
Posts: 181
Joined: 23 Aug 2018, 11:17

Re: key accidentally released while pressing hotkey, how to prevent this?

19 Sep 2020, 21:59

thank you for the reply.

I think both ideas are great but stupid me, I don't have clue how to write the proper script to play with values and such.

would you mind offering test script so it's easier to understand how it goes?

couldn't be happier!
User avatar
mikeyww
Posts: 26945
Joined: 09 Sep 2014, 18:38

Re: key accidentally released while pressing hotkey, how to prevent this?

20 Sep 2020, 09:16

It's tricky to do. Have a look at some other threads in this forum regarding key up and key down. There is quite a bit of discussion about it. Below is one general idea that you can explore.

Code: Select all

^o::
SetTimer, Wait, -350
Send O
Return

Wait:
If GetKeyState("o") {
 BlockInput, On
 Sleep, 100
 BlockInput, Off
}
SendEvent {Ctrl Up}{Shift Up}
Return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb, Google [Bot], Rohwedder and 335 guests