Sending a key twice in a row not working?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Carces
Posts: 1
Joined: 04 Dec 2021, 19:25

Sending a key twice in a row not working?

Post by Carces » 04 Dec 2021, 19:30

Hi, so I want a script that toggle on and off when I press F4, and while toggled on performs a loop.

This loop needs to send the right mouse button twice in quick succession, then wait a few seconds, then send it twice again, and so on.

I've used this same script with success before to create a loop that toggles on and off like I want, and it works here too, but for some reason it only sends the key once, not twice.

I've tried it this way:

Code: Select all

F4::
RepeatKey2 := !RepeatKey2
If RepeatKey2
	SetTimer, SendTheKey2, 300	; The "100" here is the number of milliseconds between repeats.
Else
	SetTimer, SendTheKey2, Off
Return

SendTheKey2:
Send {RButton}
Send {RButton}
Return
I've tried including a short Sleep command between the two Send commands, but it makes no difference.

I've also tried a slightly different script template, with the same results - it works, but only right clicks once, not twice.

Code: Select all


F4::
 {
   Toggle:=!Toggle

   While, Toggle
    {
		Send {RButton}
		Send {RButton}
		Sleep, 2000
    }
 }
Return

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Sending a key twice in a row not working?

Post by mikeyww » 04 Dec 2021, 21:00

I think you are mistaken. You can test your script in Notepad. Examine the KeyHistory.

Code: Select all

#InstallMouseHook
#Persistent
RepeatKey2 := !RepeatKey2
If RepeatKey2
     SetTimer, SendTheKey2, -300
Else SetTimer, SendTheKey2, Off
Return

SendTheKey2:
Send {RButton}
Send {RButton}
Return
image211204-2058-001_cr.png
Key history
image211204-2058-001_cr.png (33.21 KiB) Viewed 816 times

User avatar
boiler
Posts: 16926
Joined: 21 Dec 2014, 02:44

Re: Sending a key twice in a row not working?

Post by boiler » 04 Dec 2021, 21:00

I agree that it is likely that it actually is sending it twice, but perhaps on the receiving end, they are in too close succession to have the desired effect of two separate clicks. Try adding something like Sleep, 100 in between the two.

Post Reply

Return to “Ask for Help (v1)”