Buttons get stuck and won't released Topic is solved

Ask gaming related questions (AHK v1.1 and older)
User863
Posts: 5
Joined: 04 Feb 2021, 15:48

Buttons get stuck and won't released

Post by User863 » 08 Mar 2021, 21:57

If you run some shooter game with this script:

Code: Select all

~RButton & a::
Return
  • Then in the game press "a" to move.
  • Then without releasing "a" press the right mouse button, hold it down for a few seconds and release it.
  • And then after you release the "a" button, you will find that it is stuck (player continues to move while all buttons are physically released).
It's the same with this script:

Code: Select all

RButton & a::
Return
And with this script:

Code: Select all

RButton & a::
Send {RButton down}
Send {a down}
Loop,
	{
		GetKeyState, state, RButton, P
		If State= u
		Break
		
		GetKeyState, state, a, P
		If State= u
		Break
		
		Continue
	}
Send {RButton up}
Send {a up}
Return
Without a mouse, the same thing (only the sequence to cause sticking is longer):

Code: Select all

~a & w::
Send {w down}
Send {a down}
Loop,
	{
		GetKeyState, state, w, P
		If State= u
		Break
		
		GetKeyState, state, a, P
		If State= u
		Break
	
		Continue
	}
Send {w up}
Send {a up}
Return

So it should be or is it a bug?

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

Re: Buttons get stuck and won't released

Post by mikeyww » 09 Mar 2021, 06:54

What happens with your scripts in a text editor?

PS: note that a prefix key that is not a modifier will normally be blocked.

Explained: Custom combinations

User863
Posts: 5
Joined: 04 Feb 2021, 15:48

Re: Buttons get stuck and won't released

Post by User863 » 09 Mar 2021, 08:35

mikeyww wrote:
09 Mar 2021, 06:54
What happens with your scripts in a text editor?

PS: note that a prefix key that is not a modifier will normally be blocked.

Explained: Custom combinations

Code: Select all

MButton & a::
Return
With this script In a text editor, pressing "a" gives: aaaaaaaa...
When you press the middle mouse button: printing "a" is interrupted.
When the middle mouse button is released, printing "a" will resume.
And after the "a" is released, the printing stops.
But in games, the "a" button remains pressed forever (until be pressed and released again).
By the way, if you press the MButton button quickly (less than ~200 ms) in games, then the "a" button does not get stuck

Yes, the middle button is blocked with as it should be with prefix key (in a text editor and in games), but despite this, the "a" button continues to get stuck in games.

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

Re: Buttons get stuck and won't released

Post by mikeyww » 09 Mar 2021, 10:54

So the issue is the game's response. You might find help in the tips: https://autohotkey.com/board/topic/111737-how-to-make-ahk-work-in-most-games-the-basics/

Since you already tried to Send a up, I do not have ideas beyond this, but many find that if they follow the tips, it resolves issues.

User863
Posts: 5
Joined: 04 Feb 2021, 15:48

Re: Buttons get stuck and won't released

Post by User863 » 09 Mar 2021, 13:48

mikeyww wrote:
09 Mar 2021, 10:54
So the issue is the game's response. You might find help in the tips: https://autohotkey.com/board/topic/111737-how-to-make-ahk-work-in-most-games-the-basics/

Since you already tried to Send a up, I do not have ideas beyond this, but many find that if they follow the tips, it resolves issues.
Thanks, i found that this script does not cause a to stuck:

Code: Select all

~MButton & a::
~a & MButton::
Return
Anyway, it looks like I got what I wanted in a different way.
In case anyone is interested, here is my script that allows to perform various actions during a strafe in an FPS game, when the right button is pressed:

Code: Select all

;Remap the movement and aim buttons in the game to be able to stop the player's movement when the right mouse button is pressed

;Move left
a::
if !GetKeyState("RButton", "p")
SetTimer, SendA, 10
Return

a Up::
SetTimer, SendA, Off
Send, {Left Up} ;Remapped left move button
Send, {a Up}
Return

SendA:
Send, {Left Down} ;Remapped left move button
Return

;Move right
d::
if !GetKeyState("RButton", "p")
SetTimer, SendD, 10
Return

d Up::
SetTimer, SendD, Off
Send, {Right Up} ;Remapped right move button
Send, {d Up}
Return

SendD:
Send, {Right Down} ;Remapped right move button
Return

;Aim
RButton::
SetTimer, SendA, Off
SetTimer, SendD, Off
GoTo, Main
Return

;Main script
Main:
Send, {p Down} ;Remapped aim button

if GetKeyState("a", "p")
{
	Loop,
		{
			;Do your stuff here when "a" and "right mouse button" is pressed
			
			if !GetKeyState("RButton", "p")
			Break
			
			if !GetKeyState("a", "p")
			GoTo, Main		
		}
}

if GetKeyState("d", "p")
{
	Loop,
		{
			;Do your stuff here when "d" and "right mouse button" is pressed

			if !GetKeyState("RButton", "p")
			Break
			
			if !GetKeyState("d", "p")
			GoTo, Main	
		}
}

if GetKeyState("RButton", "p")
{
Loop,
	{
		;Do your stuff here when only "right mouse button" is pressed
		
		if !GetKeyState("RButton", "p")
		Break
		
		if GetKeyState("a", "p")
		{
		Send, {p Up} ;Remapped aim button
		GoTo, Main
		}
		
		if GetKeyState("d", "p")
		{
		Send, {p Up} ;Remapped aim button
		GoTo, Main
		}
	}
}

Send, {p Up} ;Remapped aim button

if GetKeyState("a", "p")
SetTimer, SendA, 10

if GetKeyState("d", "p")
SetTimer, SendD, 10

Return

RButton Up::
Send, {p Up} ;Remapped aim button

if GetKeyState("a", "p")
SetTimer, SendA, 10

if GetKeyState("d", "p")
SetTimer, SendD, 10

Send, {RButton Up}
Return
Last edited by User863 on 10 Mar 2021, 17:52, edited 4 times in total.

User863
Posts: 5
Joined: 04 Feb 2021, 15:48

Re: Buttons get stuck and won't released  Topic is solved

Post by User863 » 10 Mar 2021, 08:11

With some help i think i found the solution to the topic in this thread:
Why you should avoid while(GetKeyState("a", "P")) to detect release of key a
https://www.autohotkey.com/boards/viewtopic.php?t=19745

Code: Select all

~RButton & a::
Send {RButton Down}
Send {a Down}
Return

~RButton & a Up::
Send {RButton Up}
Send {a Up}
Return

Post Reply

Return to “Gaming Help (v1)”