Hotkeys with RButton while keeping original function

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
storyofwind
Posts: 4
Joined: 13 Apr 2024, 05:49

Hotkeys with RButton while keeping original function

13 Apr 2024, 06:01

Dear All:

I want to use RButton + mouse wheel to trigger hotkeyin v2.
My requests are:
1. press RButton alone can keep original function
2. RButton + Mouse tilt can triger ctrl+tab.
3. after the hotkey triggered and Rbutton release, RButton won't show the right click menu.

My first try is to use ~ modifier as follows:

Code: Select all

~RButton & WheelRight::Send "^{Tab}"
~RButton & WheelLeft::Send "^+{Tab}"
However, this cannot fulfill my 3rd requirement. When both RButton and wheel tilt release, the right click menu will still show.

I have tried another approach:

Code: Select all

RButton & WheelRight::Send "^{Tab}"
RButton & WheelLeft::Send "^+{Tab}"
RButton::Send "{RButton}"
This can almost fit my requirement, but the function of dragging by right click cannot work well since Send "{RButton}" only send one click of RButton even if I click and hold RButton.
So the "original function" of RButton is not doing all well.

Is there any other approach that can fulfill my requirement.
I found similar situation in previous post but seems no any solution.
viewtopic.php?style=2&t=44270

Thank you very much.
User avatar
mikeyww
Posts: 27011
Joined: 09 Sep 2014, 18:38

Re: Hotkeys with RButton while keeping original function

13 Apr 2024, 06:41

Welcome to this AutoHotkey forum!

I would carefully read the documentation page about custom combinations. You have not thought through what should happen at each step. First, you press RButton. What should happen next? Wait for a key to be pressed, or wheel to be activated? Drag? Something else? You have to walk through every step of each action.
ntepa
Posts: 429
Joined: 19 Oct 2022, 20:52

Re: Hotkeys with RButton while keeping original function

13 Apr 2024, 20:27

Try this:

Code: Select all

#Requires AutoHotkey v2.0

; RButton keeps its original function.
~RButton::
~RButton Up:: {
    ; If a hotkey is pressed between RButton and RButton up.
    if (A_PriorHotkey != "~RButton") {
        ; Send Esc to hide the right click menu.
        Send "{Esc}"
    }
}

#HotIf GetKeyState("RButton", "P")

    WheelRight::Send "^{Tab}"

    WheelLeft::Send "^+{Tab}"

#HotIf
User avatar
mikeyww
Posts: 27011
Joined: 09 Sep 2014, 18:38

Re: Hotkeys with RButton while keeping original function

13 Apr 2024, 22:47

This may work as well.

Code: Select all

#Requires AutoHotkey v2.0

~RButton Up:: {
 If A_PriorKey != 'RButton'
  Send '{Esc}'
}

#HotIf GetKeyState('RButton', 'P')
WheelRight::Send '^{Tab}'
WheelLeft:: Send '^+{Tab}'
#HotIf
storyofwind
Posts: 4
Joined: 13 Apr 2024, 05:49

Re: Hotkeys with RButton while keeping original function

14 Apr 2024, 04:10

Thank you for both of your replies.

The code solve the right click menu problem but in some cases, the Send "{Esc}" seems activated even when I click RButton alone.

Case 1: right click at the title bar of window (right click menu not show)

Case 2: right click at the expanded hidden tray icon (click menu shown but the expanded tray menu will hide again)

I think there might be other setting that can avoid such problems.

Thank you very much.
User avatar
mikeyww
Posts: 27011
Joined: 09 Sep 2014, 18:38

Re: Hotkeys with RButton while keeping original function

14 Apr 2024, 06:57

The two scripts are slightly different. I would try the second one.
storyofwind
Posts: 4
Joined: 13 Apr 2024, 05:49

Re: Hotkeys with RButton while keeping original function

14 Apr 2024, 10:23

mikeyww wrote:
14 Apr 2024, 06:57
The two scripts are slightly different. I would try the second one.
Both not worked well.
User avatar
mikeyww
Posts: 27011
Joined: 09 Sep 2014, 18:38

Re: Hotkeys with RButton while keeping original function

14 Apr 2024, 10:26

You can learn how to debug your script. If Esc was sent, then it means that your hotkey was triggered, and the prior key was not RButton. Thus, you can add a ToolTip or other indicator to inform you of what the prior key actually was. This is a troubleshooting step that will help you to understand what the script is doing. The KeyHistory is another helpful tool; as noted in the documentation, results there may depend on what hooks are installed.
storyofwind
Posts: 4
Joined: 13 Apr 2024, 05:49

Re: Hotkeys with RButton while keeping original function

14 Apr 2024, 18:58

mikeyww wrote:
14 Apr 2024, 10:26
You can learn how to debug your script. If Esc was sent, then it means that your hotkey was triggered, and the prior key was not RButton. Thus, you can add a ToolTip or other indicator to inform you of what the prior key actually was. This is a troubleshooting step that will help you to understand what the script is doing. The KeyHistory is another helpful tool; as noted in the documentation, results there may depend on what hooks are installed.
Thank you for the advice. I will try ToolTip and KeyHistory to track what is going on during the script running.

Thank you all for the help.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: ManualColdPadlock, mcl, Tio_oddish and 65 guests