{RButton Down} Sticking when using XButton2

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
sage2050
Posts: 6
Joined: 17 Oct 2021, 07:24

{RButton Down} Sticking when using XButton2

17 Oct 2021, 07:30

I wrote a simple script for Diablo 2 to use skills when their hotkey is pressed/held down. It works just fine for every key except mouse5 (XButton2). When I mouse5 on certain objects, right click sticks and I have to manually right click to unstick it (sometimes it takes a while to get it to unstick...). I've tried with and without the "send {RButton Up}" and both had the same behavior. code snippet below:

Code: Select all

~XButton2::
	while GetKeyState("XButton2","P")
		{
			send {Rbutton Down}
		}
		send {RButton Up}
	return
User avatar
mikeyww
Posts: 26856
Joined: 09 Sep 2014, 18:38

Re: {RButton Down} Sticking when using XButton2

17 Oct 2021, 09:01

Two things:
1. Could remove the tilde.
2. If RButton is already down, why send it down again? If you just want to click, you don't need the "down".

To remap:

Code: Select all

XButton2::RButton
sage2050
Posts: 6
Joined: 17 Oct 2021, 07:24

Re: {RButton Down} Sticking when using XButton2

17 Oct 2021, 09:08

tilde is required because the initial press sets the active skill. the while function is necessary because otherwise it will continue to send the initial command, xbutton2, while also doing the mouse down. The intended behavior is to send xbutton2 once, then hold down rmb until released.

edit: messed around with it some more. seems like removing the tilde and adding a "send {XButton2}" line in front of the while loop may have fixed it.
edit 2: no it did not. still having the same weird behavior.
User avatar
mikeyww
Posts: 26856
Joined: 09 Sep 2014, 18:38

Re: {RButton Down} Sticking when using XButton2

17 Oct 2021, 14:43

Code: Select all

XButton2::
Send {%A_ThisHotkey%}
Click, R D
KeyWait, %A_ThisHotkey%
Click, R U
Return
Suggestion: when you first post, include the intended behavior!
sage2050
Posts: 6
Joined: 17 Oct 2021, 07:24

Re: {RButton Down} Sticking when using XButton2

17 Oct 2021, 15:29

That is sound advice!
going to try this out when I get home and report back. Thanks
sage2050
Posts: 6
Joined: 17 Oct 2021, 07:24

Re: {RButton Down} Sticking when using XButton2

17 Oct 2021, 16:22

Seems like this implementation is working without a hitch - haven't been able to reproduce the sticky button

Any ideas why this was happening with XButton2 specifically? All other keys (keyboard keys) worked fine
User avatar
mikeyww
Posts: 26856
Joined: 09 Sep 2014, 18:38

Re: {RButton Down} Sticking when using XButton2

17 Oct 2021, 16:56

I think that the tilde plus sending the button down repeatedly was not your intent. If you examine KeyHistory, it will typically illuminate the issue. Another approach is to rewrite your script with characters that you can see (below).

Tilde may create a leak in this situation. Try the following demonstration in Notepad.

Code: Select all

~3::
While GetKeyState(3, "P")
 Send {4 down}
Send {4 up}
Return
sage2050
Posts: 6
Joined: 17 Oct 2021, 07:24

Re: {RButton Down} Sticking when using XButton2

19 Oct 2021, 18:48

I tried to parameterize XB2 and now it clicks once and releases.

Code: Select all

Skill_5 := "XButton2"
hotkey, *%Skill_5%, SK5

SK5:
	send {%Skill_5%}
	Click, R D
	KeyWait, {%Skill_5%}
	Click, R U
return
like last time, KB keys work fine

edit: also just took your advice and opened up key history to try to see what's going on. the click, rd, keywait, click, r u structure is sending the hotkey over and over, which is what i don't want. I want it to send the hotkey once, then hold down RMB until released.

in any case XButton2 interacting with RMB seems bugged in some kind of way.
User avatar
mikeyww
Posts: 26856
Joined: 09 Sep 2014, 18:38

Re: {RButton Down} Sticking when using XButton2

19 Oct 2021, 20:48

The KeyWait command does not use braces. See my post for an example. viewtopic.php?p=425480#p425480

Without Return before your subroutine, the subroutine will execute when the script is run. You can prove it by running the following script.

Code: Select all

#SingleInstance Force
Skill_5 := "XButton2"
Hotkey, *%Skill_5%, SK5
; Return

SK5:
SoundBeep, 1500
Send {%Skill_5%}
Click, R D
KeyWait, %Skill_5%
Click, R U
SoundBeep, 1000
Return
sage2050
Posts: 6
Joined: 17 Oct 2021, 07:24

Re: {RButton Down} Sticking when using XButton2

20 Oct 2021, 18:07

Thanks, I noticed my syntax error while my post was waiting to get approved :D
I also found that %A_ThisHotkey% does not work with labels. makes sense after some thought, just took me a few tries to figure out!
User avatar
mikeyww
Posts: 26856
Joined: 09 Sep 2014, 18:38

Re: {RButton Down} Sticking when using XButton2

20 Oct 2021, 21:30

You are right, but you can use A_ThisLabel where needed.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Giresharu, Joey5, supplementfacts and 138 guests