Keep pressing key while mousebutton is held down

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
nonvenomous
Posts: 5
Joined: 20 Aug 2018, 05:53
Contact:

Keep pressing key while mousebutton is held down

20 Aug 2018, 06:09

Hey guys,
I'm trying to figure this out on my own since longer than I would like to admit. Even as an ahk noob I was always able to achieve what I wanted to do but I think this time I need some help.

My goal is that while I'm holding down the LButton that the left arrow keeps sending left commands as long as LButton is pressed just like it would if I pressed left direct physically. That's pretty much all.
It's for a reaction based game which is usually played with the left and right arrow keys and I would like to play with the mouse buttons instead.

I played around with GetKeyState & KeyDown but it either only spams left/right uncontrollably in an infinite loop or only once.

This is probably quite straight forward and simple but I just can't get it to work.
I hope anyone can push me into the right direction. Thanks in advance.
Rohwedder
Posts: 7647
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Keep pressing key while mousebutton is held down

20 Aug 2018, 07:22

Hallo,
try:

Code: Select all

LButton::Left
F2::Suspend
F2 toggles Remapping on/off
nonvenomous
Posts: 5
Joined: 20 Aug 2018, 05:53
Contact:

Re: Keep pressing key while mousebutton is held down

20 Aug 2018, 09:15

Already tried that. Apparently for normal keys that's good enough but for mouse buttons it doesn't work.
It ends up just clicking once.
MannyKSoSo
Posts: 440
Joined: 28 Apr 2018, 21:59

Re: Keep pressing key while mousebutton is held down

20 Aug 2018, 09:45

Code: Select all

LButton::
While (GetKeyState, "LButton", "P")
Send {left}
Return
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Keep pressing key while mousebutton is held down

20 Aug 2018, 09:57

can u explain in simple steps how u want the program to behave cuz
while I'm holding down the LButton that the left arrow keeps sending left commands as long as LButton is pressed just like it would if I pressed left direct physically.
is ambiguous.

it sounds like u want to repeatedly send {Left} down+up events, while LMB is held down, but i cant be too sure:

Code: Select all

LButton::SetTimer SendLeft, 10
LButton Up::SetTimer SendLeft, Off

SendLeft:
	Send {Left}
return
nonvenomous
Posts: 5
Joined: 20 Aug 2018, 05:53
Contact:

Re: Keep pressing key while mousebutton is held down

20 Aug 2018, 15:44

MannyKSoSo wrote:

Code: Select all

LButton::
While (GetKeyState, "LButton", "P")
Send {left}
Return
When I use this the LButton doesn't do anything.
swagfag wrote:can u explain in simple steps how u want the program to behave cuz
while I'm holding down the LButton that the left arrow keeps sending left commands as long as LButton is pressed just like it would if I pressed left direct physically.
is ambiguous.

it sounds like u want to repeatedly send {Left} down+up events, while LMB is held down, but i cant be too sure:
Maybe I wasn't as clear as I hoped. I want my remap work just like it would as if I pressed and held the arrow key physically.
But instead pressing/holding the arrow key I want to use the mouse buttons.
I know this explanation still isn't great neither but I think you already understood what I'm trying to do by the script you sent.

Code: Select all

LButton::SetTimer SendLeft, 10
LButton Up::SetTimer SendLeft, Off

SendLeft:
 Send {Left}
return
This script is closer than I ever got. It reacts on how long I press the mouse button but when I tested it in game for some reason I can't turn as fast as I can with pressing the arrow key physically. Also even after I let go of the mouse button the game still thinks I'm holding it down.

Is there a way to improve the script to get the L/RButtons behave more like the arrow keys?
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Keep pressing key while mousebutton is held down

20 Aug 2018, 16:38

try this:

Code: Select all

*LButton::Send {Blind}{Left Down}
*LButton Up::Send {Blind}{Left Up}
nonvenomous
Posts: 5
Joined: 20 Aug 2018, 05:53
Contact:

Re: Keep pressing key while mousebutton is held down

21 Aug 2018, 00:40

This one only sends a single left arrow command no matter how long I keep LMB pressed.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Keep pressing key while mousebutton is held down

21 Aug 2018, 04:29

Code: Select all

#NoEnv
#SingleInstance Force
SendMode Input
SetBatchLines -1
#InstallMouseHook
#UseHook On

Loop
{
	if GetKeyState("LButton", "P")
		Send {Left}	
	else if GetKeyState("RButton", "P")
		Send {Right}	
	else
		Sleep 20
}

Esc::ExitApp

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 192 guests