I want to capture the key event “right mouse button pressed, then left mouse button pressed”. No problem in autohotkey. However I am having trouble with still allowing the right-mouse key to work alone.
1) this works:
RButton & LButton::
Send X
Return
works as expected:
- If I press right mouse button, then left mouse button, “X” is sent to the active window
- right-click event is captured by Authotkey: no context menu appears when I press the right mouse button alone. This is the intended outcome
2) this works
~RButton & LButton::
Send Y
Return
works as expected:
- If I press right mouse button, then left mouse button, “Y” is sent to the active window
- right-click event is not captured by Authotkey: context menu does appear when I press the right mouse button alone or together with the left button. This is the intended outcome
3) Now I want to do different things depending on the active window.
this does not work (careful: this will disable righ-click in every application)
#If WinActive("ahk_class MozillaWindowClass")
RButton & LButton::
Send X
Return
#If !WinActive("ahk_class MozillaWindowClass")
~RButton & LButton::
Send Y
Return
does not work as expected:
- in Firefox left-right sends X, in other applications left-right sends Y
- however, right-click is disabled in every application
What am I doing wrong here?
edit:
the goal is this: I want a global hotkey on Right+left-click with RButton & LButton . In specific applications that I have tested for compatibility, I want right+left click to suppress sending right-click, and then send right-click manually using autohotkey. However, since some applications might have trouble processing mouseevents sent by autohotkey, in all untested applications I want to use ~RButton & LButton with the ~ to pass throught right-click events
Here’s one that supports right click dragging!
It handles
RButtonmanually. WhenRButtonis pressed, it enables theLButtonhotkey and waits forRButtonto be released before deactivating it. TheRButtonhotkey uses~, which passes the click through normally.LButtonis disabled at the start by the line at the top.Another way would have been to send
{RButton Down}at the start of the hotkey and{RButton Up}at the end.In response to your edit, the only programs that reject Autohotkey’s sent events should be those that rely on low level hooks… The real trouble with the method down at the bottom is it only sends a single click, not processing holding the button. This method, and sending down and up separately, should both do that properly.
The bug with active window described at the bottom of this answer still exists, but that’s a problem with the
#IfWin[Not]Active.Old stuff
See the documentation on the ampersand (emphasis mine):
So, following that example:
Note
RButtonrequires a variant that does nothing inWinActive, at least with my testing (see below):RButton::returnSince I’m using Autohotkey standard, not Autohotkey_L, I don’t have
#Ifand the above was untested. The following I did test, and it works.An interesting bug I’ve noticed is the second (NotActive) variant applies occasionally to Firefox:
RButtondown is sentRButtonis held down, though the delay could be imperceptible, in the order of milliseconds, to infinite)RButtonup is sent, which sendsRButtonas per the documentation. Because Firefox became active in the delay between the active window check and whenRButtonis sent,RButtonis sent to Firefox.This happens when both Firefox and another window are visible, and the other window is the active one at the time of the click.
I’ve tried to fix this bug by adding an extra
IfWinNotActivecheck within theRButtonhotkey, but it did not seem to work.