Help with Right click hold + Wheel up/down

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
iorgu
Posts: 32
Joined: 03 May 2023, 17:56

Help with Right click hold + Wheel up/down

Post by iorgu » 03 May 2023, 18:08

Hello. I'm interested in a script that would sound like this:

"Hold right click and use the wheel up to zoom in, wheel down to zoom out. Releasing right click after wheel up or down was used, doesn't bring up the right click context menu".

Thanks in advance if anyone helps!
User avatar
mikeyww
Posts: 27194
Joined: 09 Sep 2014, 18:38

Re: Help with Right click hold + Wheel up/down

Post by mikeyww » 03 May 2023, 18:19

Welcome to this AutoHotkey forum!

Code: Select all

#Requires AutoHotkey v2.0
RButton::RButton
RButton & WheelUp::  Send '^{WheelUp}'
RButton & WheelDown::Send '^{WheelDown}'
iorgu
Posts: 32
Joined: 03 May 2023, 17:56

Re: Help with Right click hold + Wheel up/down

Post by iorgu » 03 May 2023, 18:37

Thanks!

Can RB holding disable the scroll function somehow? Right now i also get scrolling when using the wheel.
iorgu
Posts: 32
Joined: 03 May 2023, 17:56

Re: Help with Right click hold + Wheel up/down

Post by iorgu » 03 May 2023, 18:51

I got something! :superhappy:

Code: Select all

#Requires AutoHotkey v2.0
RButton::RButton
RButton & WheelUp::  Send '^{NumpadAdd}'
RButton & WheelDown::Send '^{NumpadSub}'
iorgu
Posts: 32
Joined: 03 May 2023, 17:56

Re: Help with Right click hold + Wheel up/down

Post by iorgu » 03 May 2023, 19:15

Now i know i can get a bit further...

NumpadAdd and NumpadSub don't zoom in every app.

I think simulating "hold ctrl+wheel" would work also.

Code: Select all

#Requires AutoHotkey v2.0
zoom := False

#HotIf GetKeyState('RButton', 'P')
WheelUp::
WheelDown:: {
 Global zoom := True
 Send '^{' ThisHotkey '}'
}
#HotIf zoom
RButton Up::Global zoom := False
#HotIf'
This code worked somehow, but it has issues, as once you release right click after using the wheel, left click no longer works outside of the first window. I need to right click and bring out context menu or right click in another window to reset things to normal.
User avatar
mikeyww
Posts: 27194
Joined: 09 Sep 2014, 18:38

Re: Help with Right click hold + Wheel up/down

Post by mikeyww » 03 May 2023, 21:26

I see what you mean.

The four-line script that you posted works well here. There are what I would call pseudo-scrolling issues that I think simply relate to zooming in and out-- how only a certain area of the page is visible, and this area changes when you zoom. I saw the same effect by using Ctrl with + and - to zoom manually even when the script was not running.
iorgu
Posts: 32
Joined: 03 May 2023, 17:56

Re: Help with Right click hold + Wheel up/down

Post by iorgu » 04 May 2023, 04:12

With these i found that you lose the Hold RB + drag ability. :(

Code: Select all

#Requires AutoHotkey v2.0
RButton::RButton
RButton & WheelUp::  Send '^{NumpadAdd}'
RButton & WheelDown::Send '^{NumpadSub}'

Code: Select all

#Requires AutoHotkey v2.0
RButton::RButton
RButton & WheelUp::  Send '^{WheelUp}'
RButton & WheelDown::Send '^{WheelDown}'
--------------------------------

With this, dragging while holding RB works fine, zooming with the wheel works fine, bit it needs another right click after finishing the zoom operation to be able to left click or do anything. If you right click outside the window where you just zoomed, no right menu comes up and you can continue

Code: Select all

#Requires AutoHotkey v2.0
zoom := False

#HotIf GetKeyState('RButton', 'P')
WheelUp::
WheelDown:: {
 Global zoom := True
 Send '^{' ThisHotkey '}'
}
#HotIf zoom
RButton Up::Global zoom := False
#HotIf

---------------------

I then removed the last part of the code to make it look like this:

Code: Select all

#Requires AutoHotkey v2.0
zoom := False

#HotIf GetKeyState('RButton', 'P')
WheelUp::
WheelDown:: {
 Global zoom := True
 Send '^{' ThisHotkey '}'
}
With this nothing gets stuck! Holding RB+drag works, zoom works, but you get the right click menu after finishing with the zoom.
It would need a RButton Up::ignore or something?
User avatar
mikeyww
Posts: 27194
Joined: 09 Sep 2014, 18:38

Re: Help with Right click hold + Wheel up/down

Post by mikeyww » 04 May 2023, 04:33

if you want to drag, then it means that the button is sent down. I am not aware of a way to send a button up without having Windows do whatever it usually does when the button is sent up. As far as I know, this is true for all keys and buttons, though most of them have no visible effect when sent up. In the case of RButton, however, this means triggering the context menu or doing whatever the button would usually do in the program.

One option that could work is adding a delay, so that drag or zoom is activated only if you hold the button by itself for a certain period. You would then be able to create cases with actions, and distinguish when a button press is intended to drag or zoom. The button would be released after a drag but not after a zoom, because the button would not be sent down in the latter case.
iorgu
Posts: 32
Joined: 03 May 2023, 17:56

Re: Help with Right click hold + Wheel up/down

Post by iorgu » 04 May 2023, 05:39

I remember back in 1999 i had this mouse - "Genius Net Mouse Pro"!

It had this "fake wheel", with two buttons used to scroll up/down, AND it had software where you could configure it's buttons. One of the options was exactly this: "Hold Right Button + Magic-Button to Zoom in/out". It was a feature advertised on the box! :lol:


I was thinking. Can a script transform a pressed RButton into Ctrl only when it also detects WheelUp or WheelDown, and when the wheel is released, RButton returns as right click.

This script does not trigger the right click menu when RButton is released!

Code: Select all

#Requires AutoHotkey v2.0
zoom := False

#HotIf GetKeyState('RButton', 'P')
WheelUp::
WheelDown:: {
 Global zoom := True
 Send '^{' ThisHotkey '}'
}
#HotIf zoom
RButton Up::Global zoom := False
#HotIf
Attachments
netmousepro.jpg
netmousepro.jpg (282.43 KiB) Viewed 1133 times
User avatar
mikeyww
Posts: 27194
Joined: 09 Sep 2014, 18:38

Re: Help with Right click hold + Wheel up/down

Post by mikeyww » 04 May 2023, 06:15

The wheel cannot be held or sent up. It has only a single, instantaneous action.
iorgu
Posts: 32
Joined: 03 May 2023, 17:56

Re: Help with Right click hold + Wheel up/down

Post by iorgu » 04 May 2023, 06:42

Yes, i was thinking each wheel action would trigger the pressed RB to become ctrl.
But i guess it would look like the first answer, which doesn't work, as it triggers lots of scrolling. You want to zoom on a picture and it jumps to another one after the second wheel action or so. Plus the right click dragging is dead.

Code: Select all

RButton::RButton
RButton & WheelUp::  Send '^{WheelUp}'
RButton & WheelDown::Send '^{WheelDown}'

----------------------------------

I'm looking at this, as it seems so so close to my needs. It doesn't trigger the right click menu after releasing RB, but i am left stuck in that window, unable to left click out of it, only inside of it. It needs another full right click wherever for the left click to work outside of it. :?

Code: Select all

#Requires AutoHotkey v2.0
zoom := False

#HotIf GetKeyState('RButton', 'P')
WheelUp::
WheelDown:: {
 Global zoom := True
 Send '^{' ThisHotkey '}'
}
#HotIf zoom
RButton Up::Global zoom := False
#HotIf
User avatar
mikeyww
Posts: 27194
Joined: 09 Sep 2014, 18:38

Re: Help with Right click hold + Wheel up/down

Post by mikeyww » 04 May 2023, 06:53

As I mentioned, the button can either be sent or not sent. To drag, it must be sent. If sent (pressed), it must be released. If released, it will trigger the context menu, etc.

You may want to start from the beginning, by writing, in order, exactly what should happen, step by step: 1. RButton is pressed. 2. ___ happens. 3. Wheel is ____. 4. ______ happens. 5. RButton is released. 6. _______ happens. You may then understand the problem more fully, and might arrive at a solution.

The delay is still a viable option for you. Assigning a different key or button sequence to handle the RButton drag is also possible. Another easy option is to change the RButton to MButton or XButton1 (for example) to enable the zoom.
iorgu
Posts: 32
Joined: 03 May 2023, 17:56

Re: Help with Right click hold + Wheel up/down

Post by iorgu » 04 May 2023, 08:04

1. RButton is pressed (and hold).
2. Nothing happens until wheel is touched, dragging works. If wheel is not touched, right click menu
3. Wheel is up/down
4. Zoom in/out happens.
5. RButton is released.
6. Noting happens, no context menu is triggered.

All 6 points work exactly as described with the latest script i mentioned, no context menu comes up after RButton is released, but you can't left click outside the window you just zoomed in/out. It needs another right click for the left click to work anywhere.
If i could figure the stuck part, i'm golden!
User avatar
mikeyww
Posts: 27194
Joined: 09 Sep 2014, 18:38

Re: Help with Right click hold + Wheel up/down

Post by mikeyww » 04 May 2023, 08:26

I guess I should have clarified. You have to write a recipe that is codable! :)

Already noted: if the button is released, then the context menu is triggered unless the button is never sent.

"If wheel is not touched" means what? The script should wait a certain amount of time for the wheel to be triggered? If so, how long? I think you then want to specify all remaining actions for two different conditions: wheel is triggered within a certain amount of time, and wheel is not triggered within a certain amount of time.

Thus, your steps need refinement and clarifications. You should also specify which parts you are doing as the user, and which parts the script is doing.
iorgu
Posts: 32
Joined: 03 May 2023, 17:56

Re: Help with Right click hold + Wheel up/down

Post by iorgu » 04 May 2023, 09:37

I can't see waiting as an option, as i press RButton + wheelup/down almost at the same time.

I was looking at XButton1 as an alternative. The back action takes place at release, so i would look to map ctrl as XButton1 pressed, but then i would deal with it's release trigger...
User avatar
mikeyww
Posts: 27194
Joined: 09 Sep 2014, 18:38

Re: Help with Right click hold + Wheel up/down

Post by mikeyww » 04 May 2023, 09:47

If you don't need to drag the X1, you can use it with the short script.
iorgu
Posts: 32
Joined: 03 May 2023, 17:56

Re: Help with Right click hold + Wheel up/down

Post by iorgu » 04 May 2023, 10:03

I tried, i get the same scrolling after a few wheelup/down. With images it's unusable, as you jump from picture to picture. This never happens when ctrl is held on the keyboard and then using the wheel.

Code: Select all

XButton1::XButton1
XButton1 & WheelUp::  Send '^{WheelUp}'
XButton1 & WheelDown::Send '^{WheelDown}'
User avatar
mikeyww
Posts: 27194
Joined: 09 Sep 2014, 18:38

Re: Help with Right click hold + Wheel up/down

Post by mikeyww » 04 May 2023, 11:27

I believe that this happens because AHK is managing the modifiers to ensure that the right keys are sent. In the case of this script, this has an unwanted "leak" effect. I think that the following adjustment takes care of it, as it uses blind mode so that the modifiers are not released.

Code: Select all

#Requires AutoHotkey v2.0
~XButton1 Up::Send('{Ctrl up}'), SoundBeep(1000)
XButton1 & WheelUp::
XButton1 & WheelDown:: {
 Send GetKeyState('Ctrl') ? '' : '{Ctrl down}'
 Send '{Blind}' (InStr(ThisHotkey, 'D') ? '{WheelDown}' : '{WheelUp}')
}
iorgu
Posts: 32
Joined: 03 May 2023, 17:56

Re: Help with Right click hold + Wheel up/down

Post by iorgu » 04 May 2023, 14:53

I just tested and there is no scroll leak! No matter how fast i hold XButton1 and go at the wheel up and down, zoom plus/minus works perfectly!

The problem is that at XButton1 release, back command is executed. :)
User avatar
mikeyww
Posts: 27194
Joined: 09 Sep 2014, 18:38

Re: Help with Right click hold + Wheel up/down

Post by mikeyww » 04 May 2023, 15:42

I guess you are at the point where you have some tools and options here, so you can experiment with your refinements to the steps-- not yet achieved by you-- and determining what should happen at every step. There is no magic to it. It is just a matter of creating a very specific description-- more specific than the one that you have written-- and then translating it into the AHK code.

More options:

Code: Select all

#Requires AutoHotkey v2.0
XButton1::Ctrl
One way to understand what is happening with the keys is to inspect the KeyHistory. This can often help in refining the script to address the various key states.
Post Reply

Return to “Ask for Help (v2)”