Sending 2 keys at once and preventing multi presses

Get help with using AutoHotkey and its commands and hotkeys
Aggronaught
Posts: 12
Joined: 02 Aug 2019, 12:55

Sending 2 keys at once and preventing multi presses

02 Aug 2019, 13:21

Hello everyone,

I'm a novice here. I just want to make a script to be able to send 2 keys with 1 key press but prevent 2nd key from being sent twice or more.

Basically, I want to remap END, to send END and DEL. However, DEL should not be send more than once every 1 sec, END needs to be send as many times as I press it.

I tried



from the documentation but it doesnt seem to do what I need it to do, cann it be done? thanks for your help.
Aggronaught
Posts: 12
Joined: 02 Aug 2019, 12:55

Re: Sending 2 keys at once and preventing multi presses

02 Aug 2019, 13:24

Sorry, the forum wont allow me to post the code, but here it is

https://p.ahkscript.org/?p=43b0d29a
gregster
Posts: 5572
Joined: 30 Sep 2013, 06:48

Re: Sending 2 keys at once and preventing multi presses

02 Aug 2019, 13:56

For some reason the if-line in its current version triggers cloudflare - also for me.

Strangely, some minor re-arrangement makes it okay. So here is your original code - slightly modified - so that it could be posted (but no answer to your question ;) ):

Code: Select all

~End::
if (A_TimeSincePriorHotkey > 500 or A_PriorHotkey != "~End" )
{
    ; Too much time between presses, so this isn't a double-press.
    Send, Del
    return
}
Send, End
return
User avatar
tank
Posts: 2855
Joined: 28 Sep 2013, 22:15
Facebook: charlie.simmons.7334
Google: ttnnkkrr
GitHub: ttnnkkrr
Location: Irving TX
Contact:

Re: Sending 2 keys at once and preventing multi presses

10 Aug 2019, 13:30

Sorry about the posting issue it has just been resolved
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
https://www.facebook.com/ahkscript.org
If you have forum suggestions please submit a pull request
Check Out WebWriter
Thanks Tank :thumbup:
gregster
Posts: 5572
Joined: 30 Sep 2013, 06:48

Re: Sending 2 keys at once and preventing multi presses

10 Aug 2019, 23:37

Thanks, @tank, for fixing it.

@Aggronaught, you might want to try this:

Code: Select all

last_del := 0    	; put this into the auto-execute section of the script (top of the script)

~End::
if ((A_tickcount - last_del) > 1000)
{
	last_del := A_tickcount
	Send, {Del}
}
return
A_tickcount is a built-in variable that returns the time in milliseconds since the system started.
Special keys like Del need to be put between { }, if you want to send them.
The ~ modifier makes sure that the End key is sent anyway with every key press.
Aggronaught
Posts: 12
Joined: 02 Aug 2019, 12:55

Re: Sending 2 keys at once and preventing multi presses

13 Aug 2019, 14:03

gregster wrote:
10 Aug 2019, 23:37
Thanks, @tank, for fixing it.

@Aggronaught, you might want to try this:

Code: Select all

last_del := 0    	; put this into the auto-execute section of the script (top of the script)

~End::
if ((A_tickcount - last_del) > 1000)
{
	last_del := A_tickcount
	Send, {Del}
}
return
A_tickcount is a built-in variable that returns the time in milliseconds since the system started.
Special keys like Del need to be put between { }, if you want to send them.
The ~ modifier makes sure that the End key is sent anyway with every key press.
thank you, is there anyway to check if DELETE key has been pressed manually? I run into the problem where I press DELETE manually because the script is either slow/too fast..I would like to keep the script but be able to check for manual DELETE press on top of the scripted press.

so it would work like this

When i press END,
it sends END everytime
only sends DELETE every 1 secs
but if it would check if I had pressed DELETE manually in the last second and if i had pressed DELETE manually in the previous second, it won't send DELETE again.

thanks a lot again.
gregster
Posts: 5572
Joined: 30 Sep 2013, 06:48

Re: Sending 2 keys at once and preventing multi presses

13 Aug 2019, 20:54

If I understand correctly, this small change might help:

Code: Select all

last_del := 0    	; put this into the auto-execute section of the script (top of the script)

~Del::last_del := A_tickcount

~End::
if ((A_tickcount - last_del) > 1000)
{
	last_del := A_tickcount
	Send, {Del}
}
return
Aggronaught
Posts: 12
Joined: 02 Aug 2019, 12:55

Re: Sending 2 keys at once and preventing multi presses

14 Aug 2019, 10:07

works perfectly, thank you so much.

Return to “Ask For Help”

Who is online

Users browsing this forum: alexsu, Bing [Bot], Muzzy, Rohwedder, TAC109 and 40 guests