Hold one key down, send 1 key and LMB alternately Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Automatey
Posts: 2
Joined: 13 Oct 2021, 23:43

Hold one key down, send 1 key and LMB alternately

Post by Automatey » 13 Oct 2021, 23:58

Hello scripters,

I am a beginner and I've watched a couple of forum posts to get started somewhere.
What I'm trying to do is:

1 key to toggle the entire script, let's say "1".
When active, the script should always keep the "G" key down.
While keeping the "G" key down it should rotate (with a minor interval) between sending "RMB" and "H" indefinitely.

What does this require? I've seen KeyDown, SendInput, Toggle, If Else Statements etc.

I have found this for example:

Code: Select all

1::
KeyDown := !KeyDown
If KeyDown
	SendInput {g down}
Else
	SendInput {g up}
Return
[Mod edit: [code][/code] tags added.]

But I can't just add send, sleep, send, sleep for the two things it has to rotate between.

Any help is appreciated.

Thank you in advance :clap:

Rohwedder
Posts: 7644
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Hold one key down, send 1 key and LMB alternately  Topic is solved

Post by Rohwedder » 14 Oct 2021, 01:53

Hallo,
try:

Code: Select all

1:: ;On/Off with key 1
If KeyDown := !KeyDown
{
	SetTimer, Rmb, 200 ;every 200ms
	SendInput, {g down}
}
Else
{
	SetTimer, Rmb, Off
	SendInput, {g up}
}
Return
Rmb:
IF Rmb := !Rmb
	SendInput, {RButton}
Else
	SendInput, h
Return
or:

Code: Select all

1::SendInput,% (KeyDown:=!KeyDown)?"{g down}":"{g up}"
1 Up::SetTimer, vk-1,% KeyDown?200:"Off" ;every 200ms
vk-1::SendInput,% (Rmb:=!Rmb)?"{RButton}":"h"

Automatey
Posts: 2
Joined: 13 Oct 2021, 23:43

Re: Hold one key down, send 1 key and LMB alternately

Post by Automatey » 15 Oct 2021, 19:51

Rohwedder wrote:
14 Oct 2021, 01:53
Hallo,
try:

Code: Select all

1:: ;On/Off with key 1
If KeyDown := !KeyDown
{
	SetTimer, Rmb, 200 ;every 200ms
	SendInput, {g down}
}
Else
{
	SetTimer, Rmb, Off
	SendInput, {g up}
}
Return
Rmb:
IF Rmb := !Rmb
	SendInput, {RButton}
Else
	SendInput, h
Return
or:

Code: Select all

1::SendInput,% (KeyDown:=!KeyDown)?"{g down}":"{g up}"
1 Up::SetTimer, vk-1,% KeyDown?200:"Off" ;every 200ms
vk-1::SendInput,% (Rmb:=!Rmb)?"{RButton}":"h"
Wow, this is perfect. Thank you so much! :thumbup: :superhappy:

Post Reply

Return to “Ask for Help (v1)”