Trying to get keystrokes and simultaneous mouse actions on different circumstances... to no avail. Topic is solved

Ask gaming related questions (AHK v1.1 and older)
User avatar
Maped
Posts: 23
Joined: 08 Jul 2018, 15:52

Trying to get keystrokes and simultaneous mouse actions on different circumstances... to no avail.

08 Jul 2018, 16:15

Hello everyone. I spent whole day studying AHK and I cannot find solution for my problem.
This is what I'm trying to do: - press left mouse button (LMB click) to start an action and also send a keystroke {L} but.. when i hold LMB I would like it to keep it that way for as long as I am pressing LMB, and also repeatedly send a keystroke {L} (or just send it once on LMB down). All of this should work no matter what other buttons are pressed.
I tried a lot of combinations with if/else/loops/until and stuff like that but apparently I do not understand AHK well enough to be able to make a functional script.

First I came up with this:

Code: Select all

*LButton::
While GetKeyState ("LButton","P")
	{
	Send {LButton}
	Send {L}
	}
return
Later i tried something I found on forum:

Code: Select all

*LButton::
Send {LButton down}
random, time, 25, 50
sleep, time
GetKeyState("LButton","P")
if state = D
	Send {LButton down}
else
	Send {LButton}
random, time, 25, 50
sleep, time
Send {LButton up}
return
But it locks the LMB and I do not know where I should put the keystroke {L}

This is another thing I came up with :facepalm: :

Code: Select all

*LButton::
loop, 2
{
Send {l down}
KeyWait, LButton
GetKeyState, state, LButton, P
if state = P
	Send {LButton down}
else
	Send {LButton}
Send {l up}
}
return

Well I hope you get what I mean. Show me the way please...
Rohwedder
Posts: 7622
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Trying to get keystrokes and simultaneous mouse actions on different circumstances... to no avail.  Topic is solved

09 Jul 2018, 04:26

Hallo,
I fixed your script. There was a space between GetKeyState and ("LButton","P")

Code: Select all

*LButton::
While GetKeyState("LButton","P")
	{
	Send {LButton}
	Send {L}
	}
return
But maybe this is better?

Code: Select all

*LButton::
While GetKeyState("LButton","P")
{
	Send {Blind}{LButton}l
	Sleep, 100
}
Return
or if you don't want to spam Clicks:

Code: Select all

~*LButton::
While GetKeyState("LButton","P")
{
	Send {Blind}l
	Sleep, 100
}
Return
User avatar
Maped
Posts: 23
Joined: 08 Jul 2018, 15:52

Re: Trying to get keystrokes and simultaneous mouse actions on different circumstances... to no avail.

09 Jul 2018, 06:59

Thank you! :>
Im surprised that Space was the issue. Now it works almost as good as I wanted. (proud me)

The last script works great but it does not spam. I do not need it but it would be nice to know how to do it.

"~" made a huge difference.
Why sleep for 100ms? I have noticed that in many scripts people add sleep but it is useless. Or is it not?

Code: Select all

~*LButton::
While GetKeyState("LButton","P")
{
	Send {Blind}l
}
Return
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: Trying to get keystrokes and simultaneous mouse actions on different circumstances... to no avail.

09 Jul 2018, 07:09

Doing Send {Blind}l with no sleep in-between will most likely result in there being no delay between the release and the next press - many games will not recognize a key that is released then immediately re-pressed as having ever been released at all. Often you need 20-50ms for the game to register the release.
User avatar
Maped
Posts: 23
Joined: 08 Jul 2018, 15:52

Re: Trying to get keystrokes and simultaneous mouse actions on different circumstances... to no avail.

09 Jul 2018, 07:20

Does this randomize time delay between 25 and 50?:

Code: Select all

random, time, 25, 50
sleep, time
It shows me that there is a random response 0,03 or 0,05. How to check how long is the delay?
015: While,GetKeyState("LButton","P")
021: Return (0.73)
015: While,GetKeyState("LButton","P")
017: Send,{Blind}l (0.01)
018: Random,time,25,50
019: Sleep,time (0.05)
020: }
015: While,GetKeyState("LButton","P")
017: Send,{Blind}l (0.02)
018: Random,time,25,50
019: Sleep,time (0.03)
020: }
015: While,GetKeyState("LButton","P")
021: Return (0.13)
015: While,GetKeyState("LButton","P")
017: Send,{Blind}l (0.02)
018: Random,time,25,50
019: Sleep,time (0.03)
020: }
015: While,GetKeyState("LButton","P")
017: Send,{Blind}l (0.02)
018: Random,time,25,50
019: Sleep,time (0.05)
020: }
User avatar
Maped
Posts: 23
Joined: 08 Jul 2018, 15:52

Re: Trying to get keystrokes and simultaneous mouse actions on different circumstances... to no avail.

09 Jul 2018, 13:41

Any suggestions on how to add click spam?

Code: Select all

~*LButton::
While GetKeyState("LButton","P")
{
	Send {Blind}l
	random, time, 25, 50
	sleep, time
}
Return

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: ReyAHK and 44 guests