Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7844243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:48:56+00:00 2026-06-02T16:48:56+00:00

I want to capture the key event right mouse button pressed, then left mouse

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T16:48:57+00:00Added an answer on June 2, 2026 at 4:48 pm

    Here’s one that supports right click dragging!

    Hotkey, LButton, off
    
    #IfWinActive ahk_class MozillaWindowClass
    RButton & LButton::
        Send X
    Return
    
    RButton::return
    
    #IfWinNotActive ahk_class MozillaWindowClass
    ~$RButton::
    Hotkey, LButton, on
    while GetKeyState("RButton", "P") {
        continue
        }
    Hotkey, LButton, off
    Return
    
    LButton::Send Y
    Return
    

    It handles RButton manually. When RButton is pressed, it enables the LButton hotkey and waits for RButton to be released before deactivating it. The RButton hotkey uses ~, which passes the click through normally.

    LButton is 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):

    You can define a custom combination of two keys (except joystick buttons) by using " & " between them. In the below example, you would hold down Numpad0 then press the second key to trigger the hotkey:

    Numpad0 & Numpad1::MsgBox You pressed Numpad1 while holding down Numpad0.
    Numpad0 & Numpad2::Run Notepad
    

    In the above example, Numpad0 becomes a prefix key; but this also causes Numpad0 to lose its original/native function when it is pressed by itself. To avoid this, a script may configure Numpad0 to perform a new action such as one of the following:

    Numpad0::WinMaximize A   ; Maximize the active/foreground window.
    Numpad0::Send {Numpad0}  ; Make the release of Numpad0 produce a Numpad0 keystroke. See comment below.
    

    The presence of one of the above hotkeys causes the release of Numpad0 to perform the indicated action, but only if you did not press any other keys while Numpad0 was being held down.

    So, following that example:

    #If WinActive("ahk_class MozillaWindowClass")
    
    RButton & LButton::
        Send X
    Return
    
    RButton::return
    
    #If !WinActive("ahk_class MozillaWindowClass")
    RButton & LButton::
        Send Y
    Return
    
    RButton::Send {RButton}
    

    Note RButton requires a variant that does nothing in WinActive, at least with my testing (see below): RButton::return


    Since I’m using Autohotkey standard, not Autohotkey_L, I don’t have #If and the above was untested. The following I did test, and it works.

    #IfWinActive ahk_class MozillaWindowClass
    RButton & LButton::
        Send X
    Return
    
    RButton::return
    
    
    #IfWinNotActive ahk_class MozillaWindowClass
    RButton & LButton::
        Send Y
    Return
    
    RButton::Send {RButton}
    

    An interesting bug I’ve noticed is the second (NotActive) variant applies occasionally to Firefox:

    1. Another window is active
    2. RButton down is sent
    3. Firefox is not active, so the second variant is processed
    4. <delay> (RButton is held down, though the delay could be imperceptible, in the order of milliseconds, to infinite)
    5. Firefox becomes active
    6. <delay> (still held down)
    7. RButton up is sent, which sends RButton as per the documentation. Because Firefox became active in the delay between the active window check and when RButton is sent, RButton is 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 IfWinNotActive check within the RButton hotkey, but it did not seem to work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to capture key event at all time, even when my application is
I want to capture the browser window/tab close event. I have tried the following
I want to be able to capture key events inside a service I am
I want to register when the key Tab has been pressed, but can't figure
i want to capture the fn-key on the Mac keyboard in my CMS application.
I want to manually invoke enter key press event on textbox through JS or
So I want to capture some key-commands in our Docuement-level Excel VSTO addin. I
I want to capture the text from the textbox when enter key is hit.
I want to capture input charcters in text box, convert then according to a
I want to capture the HTTP request header fields, primarily the Referer and User-Agent,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.