GetKeyState not working as expected

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
WalterRoberts
Posts: 67
Joined: 25 Feb 2020, 20:00

GetKeyState not working as expected

14 May 2020, 16:07

Code: Select all

Sleep 2000
Loop, 4
if GetKeyState("RButton")
    MsgBox RButton is down.
else
    MsgBox RButton is NOT down.

; Once the following custom combinations are added 
; GetKeyState("RButton") does not get recognized anymore 
; even though RButton is physically down
$RButton::Send {RButton}
RButton & Enter::Msgbox First RightMouseButton and then Enter pressed
Does anybody know the solution to this problem?
User avatar
Yakshongas
Posts: 590
Joined: 21 Jan 2020, 08:41

Re: GetKeyState not working as expected

14 May 2020, 17:22

Code: Select all

Sleep 2000
Loop
{
    if (GetKeyState("RButton"))
    {
        ToolTip, RButton Is Down 
    }
    else
    {
        ToolTip, RButton is NOT down.
    }
}
Return
~RButton & Enter::Msgbox First RightMouseButton and then Enter pressed
Please mark your topics as solved if you don't need any further help. ✅

Need a little more help? Discord : Yakshongas#9893 🕹
WalterRoberts
Posts: 67
Joined: 25 Feb 2020, 20:00

Re: GetKeyState not working as expected

14 May 2020, 21:38

Right, I have also tried this, but the problem with this specific syntax is when using "RButton & Enter" a right-click is performed after RButton is released which would basically make all custom combinations of "RButton & ______" useless.
This gets solved with "$RButton::Send {RButton}", but then GetKeyState("RButton") does not recognize the key state anymore as stated above.
I have also tried to work around this issues with the following code, but in this case it basically does not change anything. Also removing the tilde in this context is the same like when writing "$RButton::Send {RButton}".

Code: Select all

~RButton::
	KeyWait RButton
	If (A_PriorKey = "RButton")
		Send {RButton}
Return

This problem seems trickier than I thought.
GEV
Posts: 1002
Joined: 25 Feb 2014, 00:50

Re: GetKeyState not working as expected

15 May 2020, 12:31

What about this

Code: Select all

~*RButton Up::
If (A_PriorKey != "RButton")
	Send, {Esc}
return
WalterRoberts
Posts: 67
Joined: 25 Feb 2020, 20:00

Re: GetKeyState not working as expected

17 May 2020, 10:00

This comes pretty close, as it actually does prevent a right-click from occurring when any random combination is pressed, except that it still does not work with any custom created combination (like ~RButton & Enter::Msgbox First RightMouseButton and then Enter pressed in this example). So, the initial problem persists...

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Joey5 and 237 guests