0

I have successfully made it so that when I hold down the right mouse button I can control the system volume with The scroll wheel. But my problem now is that every time that I release the right button it still right clicks even if I have changed the volume.

I want to retain the normal right click, but not when I have used the right mouse button in a macro (then it should ignore the release of the right mouse button). How do I best add a script to ignore mouse clicks in this situation?

This is what I use at the moment:

~RButton & WheelUp::Send {Volume_Up}

And I like it for its brevity (also, other ways have shown to be buggy), so I hope that there is a simple solution that I have missed.

I think it should be possible to have a timer based solution that works (like for double right click as shortkeys), but I have been unable to use that solution.


Here are solutions I have found that Don't quite solve it:

RButton & WheelUp::Send {Volume_Up} ; inactivates right click 


RButton:: click right ; gets right click back, but unable to have right click pressed 
;(dragging things with right click, etc would be impossible) 
RButton & WheelUp:: Send {Volume_Up}
RButton & WheelDown::Send {Volume_Down}    
3
  • Using a normal key as modifier makes the key lose its original function by design. The behavior on my machine isn't as you described: No right click ever gets sent to the active window (neither in conjunction with WheelUp nor by itself). There's several workarounds, but they all won't completely restore RButtons native behavior. If you don't mind that the right click is only sent upon release of RButton (that is, things like right click drag won't work anymore), I can offer you a solution. Commented Jul 18, 2014 at 8:47
  • Ah, was missing a ~ in the beginning, thank you for pointing that out. Commented Jul 18, 2014 at 9:49
  • This doesn't really answer your question directly, but I thought it was worth mentioning. I have a project that deals with adjusting the volume with scroll wheel here. You might get some ideas from it. Commented Jul 18, 2014 at 12:22

3 Answers 3

1

OK, here is a better solution, I think.

~RButton & WheelUp::
 Send {Volume_Up}
 SetTimer, CloseContextMenu, 50
return

~RButton & WheelDown::
 Send {Volume_Down}
 SetTimer, CloseContextMenu, 50
return

 CloseContextMenu:
KeyWait, RButton, R
WinGetTitle, active_title, A
WinGetClass, active_class, A
WinActivate, ahk_class Progman      ;desktop
WinWaitActive, ahk_class Progman
Send, {ALT Down}{ALT Up}        ; try also: Send, {Esc} (remove the Alt command)
SetTimer, CloseContextMenu, off
WinActivate,  %active_title% ahk_class %active_class%
return
Sign up to request clarification or add additional context in comments.

8 Comments

This is still suboptimal, as the ALT command could affect other commands I use directly after this command. It is however the best solution as of yet.
If the ALT command could affect other commands after (3)0 ms (A_PriorHotKey) you could add some Sleep or something else before the last return
Ok, seems like this solved 90% of my issues. The one issue (that I have found after 30 minutes of testing it) is with Total Commander. And it occurs in two ways: 1) when I highligt (using the right click, ergo inactivating the menu that would pop up. This leads to it alt clicking which has the effect that alt is changing the behavior of Total Commander (in this case just highlighting the menu bar). 2) When files are highlighted And Total Commander sends right click (due to not moving the mouse while changing volume), all files that are selected are unselected.
You can activate another window before sending the Alt command in your script eg. the desktop: " ...WinActivate, ahk_class Progman ---> WinWaitActive, ahk_class Progman ---> Send, {ALT Down}..."
Not sure how you mean I could do this without making it a lot slower... Could you update your answer to show how this would solve it?
|
1
~RButton & WheelUp::
 Send {Volume_Up}
 SetTimer, CloseContextMenu, 50
return

~RButton & WheelDown::
 Send {Volume_Down}
 SetTimer, CloseContextMenu, 50
return

CloseContextMenu:
 KeyWait, RButton, R
 Send, {Esc}
 SetTimer, CloseContextMenu, off
return

3 Comments

This can have disastrous consequences if the active window doesn't open a native context menu after a right click, e.g. in many games, other full screen applications, browsers when websites have the native context-menu disabled, etc. Worst case: The active window gets closed if it reacts to the {ESC} accordingly.
I haven't yet seen a program or main window that gets closed with ESC. And these "disastrous consequences" are easy to avoid if you make these hotkeys or the command "Send, {Esc}" context-sensitive.
I agree that this is suboptimal, as any command like esc could lead to unintended consequences depending on program. It is however a solution that is better than the original behavior.
1

Try also this:

#NoEnv 
SendMode Input 
#SingleInstance Force
Process, Priority, ,High
#InstallKeybdHook
#InstallMouseHook
#UseHook 

#MenuMaskKey vk07  ;  is used to mask Win or Alt keyup events
; http://ahkscript.org/docs/commands/_MenuMaskKey.htm
return


~RButton & WheelUp::
 Send {Volume_Up}
 SetTimer, CloseContextMenu, 50
return

~RButton & WheelDown::
 Send {Volume_Down}
 SetTimer, CloseContextMenu, 50
return

 CloseContextMenu:
KeyWait, RButton, R
Send, {ALT Down}{ALT Up}
SetTimer, CloseContextMenu, off
return

2 Comments

With one simple modification it worked perfectly (as far as I have tested): Send, {ALT Down} Sleep, 30 Send, {ALT Up} Send {RCtrl DOWN}{Alt DOWN}{Alt UP}{RCtrl UP}
I have updated the answer to the way that works for me and accepted it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.