Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Disable context menu - combo hotkey with RButton


  • Please log in to reply
13 replies to this topic
flipswitch5point
  • Members
  • 31 posts
  • Last active: Jan 13 2012 07:08 PM
  • Joined: 11 May 2011
~RButton & WheelUp::Send {Volume_Up}
~RButton & WheelDown::Send {Volume_Down}

I desperately want this to work without the context menu. Taking out the ~ messes with normal functionality and I just can't seem to get KeyWait to work properly :S

I figure it should be something like

~RButton & WheelUp::
Send {Volume_Up}
KeyWait, RButton, U
Sleep, 200 ;if necessary
Send {Esc}

~RButton & WheelDown::
Send {Volume_Down}
KeyWait, RButton, U
Sleep, 200 ;if necessary
Send {Esc}

But this does nothing...

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
Perhaps...
RButton & Wheelup::Send {Volume_up}
RButton & Wheeldown::Send {Volume_down}
RButton::Send {RButton}
:?:

flipswitch5point
  • Members
  • 31 posts
  • Last active: Jan 13 2012 07:08 PM
  • Joined: 11 May 2011
Thanks, but I've considered that, and I definitely need right click and drag functionality. Any other ideas?

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
Here is the problem with that: if you need right-click-and-drag functionality, how should AHK know when to block the RButton?

RButton is pressed down
<should I block it or not?>
RButton is released
<oh no, I guess I shouldn't have blocked it.>

RButton is pressed down
<should I block it?>
Wheel is scrolled up
<oh no, I should have blocked RButton! It's too late now!>
<Volume_up sent>
RButton released
<well, nothing I can do about that context menu...>



jpjazzy
  • Members
  • 800 posts
  • Last active: Dec 17 2014 07:22 AM
  • Joined: 16 Feb 2010
:lol: Nimda, I am sorry but you just made my day with that little quote... I know it's supposed to just illustrate what was happening, but personifying AHK scripting... Only a real scripter could do that. 8) Sorry. Just had to tell you.
AutoHotkey Basic - Windows 7
Posted Image

Gogo
  • Guests
  • Last active:
  • Joined: --
AHK_L is required
~RButton Up::
  If A_PriorHotkey in WheelUp,WheelDown
     Send {Escape}
  return

#If GetKeyState("RButton", "P")  ; !!! works on ALL next hotkeys

WheelUp:: Send {Volume_up}
WheelDown:: Send {Volume_down}


flipswitch5point
  • Members
  • 31 posts
  • Last active: Jan 13 2012 07:08 PM
  • Joined: 11 May 2011
THANK YOU!! That's absolutely brilliant. Works like a charm. The context menu doesn't even flash! :O

flipswitch5point
  • Members
  • 31 posts
  • Last active: Jan 13 2012 07:08 PM
  • Joined: 11 May 2011
Okay, I decided that I'd like a simple OSD to flash whenever the hotkeys are activated. So far, all I've come up with is an OSD that won't show, or one that's always there. I have no idea how to modify the script to trigger the OSD without compromising the functionality.

I tried some A_ThisHotKey stuff, some If's and While's and even just placing it under the hotkeys (this last one results in the Volume_Up/Volume_Down being triggered just once - as if you were to just press it and release it rather than the effect rendered by holding it down, or in this case, keep rolling the mouse wheel)

Just spent 6 hours playing around, gonna take a break now, any ideas on how to do this?

The latest edit is below (OSD permanent)
* - VA.ahk and Autohotkey_L required


#SingleInstance force
#Include *i VA.ahk
#NoEnv
#InstallMouseHook

FileDelete, PIDmv.txt   ;for another script
FileAppend, % DllCall("GetCurrentProcessId"), PIDmv.txt ;for another script

SetTimer, Rfrsh, 60 ;update frequency for OSD

;OSD settings
volume := VA_GetMasterVolume()
Gui, Color, 000000
Gui +LastFound 
WinSet, TransColor, 000000
Gui, Font, bold cLime, System
Gui +AlwaysOnTop -Caption
Gui, Add, Text,, Volume - %volume%`%
Gui, Show,, Volume
return

;OSD updater
Rfrsh:
  SetControlDelay -1
  volume := VA_GetMasterVolume()
  GuiControl,, Volume, Volume - %volume%`%
Return

;Hotkeys
~RButton Up::
  If A_PriorHotkey in WheelUp,WheelDown
     Send {Escape}  
  return

#If GetKeyState("RButton", "P")  ; !!! works on ALL next hotkeys
  WheelUp:: Send {Volume_up}
  WheelDown:: Send {Volume_down}


flipswitch5point
  • Members
  • 31 posts
  • Last active: Jan 13 2012 07:08 PM
  • Joined: 11 May 2011
Think I figured it out, removed the mouse hook and played around some more with the phrasing, etc. (What I think is) the final edit is below.



#SingleInstance force
#Include *i VA.ahk
#NoEnv

FileDelete, PIDmv.txt   ;for another script
FileAppend, % DllCall("GetCurrentProcessId"), PIDmv.txt ;for another script

SetTimer, Rfrsh, 60 ;update frequency for OSD

;OSD settings
volume := VA_GetMasterVolume()
Gui, Color, 000000
Gui +LastFound 
WinSet, TransColor, 000000
Gui, Font, bold cLime, System
Gui +AlwaysOnTop -Caption
Gui, Add, Text, w150, Volume - %volume%`%
;Gui, Show,, Volume
return

;OSD updater
Rfrsh:
  SetControlDelay -1
  volume := VA_GetMasterVolume()
  GuiControl,, Volume, Volume - %volume%`%
Return

;Hotkeys
~RButton Up::
  If A_PriorHotkey in WheelUp,WheelDown
      Send {Escape}  
      Gui Hide
  return


#If GetKeyState("RButton", "P")  ; !!! works on ALL next hotkeys

  WheelUp::
    {
      Send {Volume_up}
      Gui, Show, Center, Volume
    Return
    }
    
  WheelDown::
    {
      Send {Volume_down}
      Gui, Show, Center, Volume
    Return
    }


Scoox
  • Members
  • 194 posts
  • Last active: Jun 09 2017 03:34 AM
  • Joined: 28 Nov 2010
This thread has inspired me greatly. What I've been trying to achieve for over a year was the following:

LButton & Rbutton::SendInput {F13}
RButton & Lbutton::SendInput {F14}

I use these two hotkeys to pop up two floating True Launch Bar (http://www.truelaunchbar.com) menus that conveniently allow me to access all my apps and folders from anywhere on the screen. The floating menus look like this right now (they keep evolving though):

Favorite apps and folders:
Posted Image

Floating Start menu:
Posted Image

I can drag and drop file and folders onto these menus in the same way it was possible with XP's Quick Launch, excep that True Launch Bar can be popped up at the mouse cursor and is infinitely customizable. I can't recommend it highly enough.

The above hotkeys work fine but I lose the right-click-drag functionality, which is a must in a several applications I use (e.g. secondary colour in drawing apps such as MS Paint just to name a common one).

I ended up buying a 5-button mouse and with the XButtons I was able to what I wanted and more. But I still wanted to find a solution to the above problem, and here it is:

#If GetKeyState("RButton", "p")  ; !!! works on ALL next hotkeys
	;Open floating Start menu - Works!!
	LButton::
		Goto Method_2
		Method_1: ;Pops up menu after releasing RButton
			SendInput {RButton Up}
			SendInput {Esc}
			KeyWait, Rbutton ;As soon as the RButton is released, send Esc to kill the context menu forthwith
			SendInput {Esc}
			IfWinExist, ahk_class TrueLaunchBarMenu
				SendInput {F14} ;Close first then re-open
			SendInput {F14}
		Return
		Method_2: ;Pops up menu immediately. Downside: if you move the mouse off TLB it does not work
			SendInput {RButton Up}
			SendInput {Esc}
			SendInput {F14}
			Sleep 100 ;Wait for menu to be displayed
			MouseMove, 7, , 0, R ;Move mouse over the TLB menu because if you release the RButton while outside the TLB area you will open the Explorer context menu which is unwanted.
			KeyWait, RButton ;When RButton released, TLB contect menu opens
			SendInput {Esc} ;Close context menu
		Return

#If GetKeyState("LButton", "p")  ; !!! works on ALL next hotkeys
	RButton::SendInput {F13} ;Launch floating Favourites menu
	;... Other LButton & ? commands go here.
	Example: Use LButton as Ctrl
	c::SendInput {LButton Up}^c ;Copy
	v::SendInput {LButton Up}^v ;Paste
	x::SendInput {LButton Up}^x ;Cut
	;... etc
#If

Obviouly I didn't include all my hotkeys in the above code but you can easily have a mouse on steroids this way. I use RButton & MButton to go back in browsers (Explorer, Firefox, IE, etc) and to undo in all other apps, MButton & RButton to go forward in browsers and to redo in all other apps. Using my 5-button mouse alone I am able to launch over 30 hotkeys. It's truly amazing.

I also have a "hot-band" along the top of my screen. Depending on where the mouse is I scroll and adjust display brightness, master volume and window transparency. No need to hold down shift. Scrolling over the taskbar switches apps.

Excuse the incredibly messy post, it's nearly 2 A.M. and English isn't my mother tongue. I just felt the urge to share my findings before going to sleep. If anyone is interested or has any questions I will be glad to provide further insight.

Scoox
  • Members
  • 194 posts
  • Last active: Jun 09 2017 03:34 AM
  • Joined: 28 Nov 2010
Today I managed to come up with a simplified version of the above code. The key is suppressing the context menu when the RButton is released rather than when it is pressed down, i.e. on the key-up event. This yields very predictable behaviour and neater, simpler code.

;This code allows you to use both LButton and RButton as a modifier keys whilst preserving itheir native click-and drag behaviour.

~LButton & RButton::
	SendInput {F13}
	MsgBox You pressed LButton & RButton
Return

~RButton & LButton::
	SuppressContextMenu(50)
	SendInput {F14} ;Note: After keystrokes and before menu/msgbox
	MsgBox You pressed RButton & LButton
Return

;Below hotkeys allow back-forward in browsers. This is an over-simpllified example. On my script the behaviour of these hotkeys depends on the active window, so that in some windows I get Undo-Redo instead of Back-Forward.

MButton & RButton::
	SendInput {Browser_Forward}
	MsgBox You pressed MButton & RButton
Return

RButton & MButton::
	Sendinput {Browser_Back}
	SuppressContextMenu() ;Note: After keystrokes and before menu/msgbox
	MsgBox You pressed RButton & LButton
Return

;SuppressContextMenu()
; Use this function whenever you use the RButton as modifier, to prevent the associated context menu from popping up.
; Arguments:
; - Delay: A delay in ms added at the end to eliminate a race condition which occurs when you use the RButton to open another menu (e.g. a True Launch Bar menu). If Delay is omitted or less than or equal to 0, no delay will be inserted.
; Usage: Call SuppressContextMenu() always before code that opens a menu, dialogue, GUI or MsgBox, and specify a delay (50ms typically works well). Place it before code that sends keystrokes so that the keystrokes are sent only after you release RButton, or after the code so that the keystrokes are sent immediately as soon as the hotkey is pressed.

SuppressContextMenu(Delay=0)
{
	KeyWait RButton
	SendInput {Esc}
	If (Delay > 0)
		Sleep %Delay%
}

Works very well!

Scoox
  • Members
  • 194 posts
  • Last active: Jun 09 2017 03:34 AM
  • Joined: 28 Nov 2010
Here is my neatest solution so far. It allows for commands to be run instantly on key down rather than on key up. The disadvantage of this script is that you have to define a group with the various context menu classes you come across. Each time you install a new app there is a chance that it's context menu might not be a standard one (Mozilla Firefox is a good example), but the advantage is that it is very reliable.

The advantage of my previous script was that it worked with every application, but the disadvantage was that when using RButton as a modifier the script needed to wait for RButton to be released before running the commands.

On my system I am currently using the new version, as listed below.

;Context menus group
;Add your own so that script works with any software.
GroupAdd, ContextMenus, ahk_class #32768 ;Generic Windows context menu
GroupAdd, ContextMenus, ahk_class MozillaDropShadowWindowClass ;Firefox context menu
GroupAdd, ContextMenus, ahk_class QPopup ;Anki context menu

;KillContextMenu() should be placed at the top of a hotkey's code. Its purpose is to suppress any context menus typically resulting from pressing a hotkey where RButton is used as a modifier.
KillContextMenu()
{
	SetTimer, TimerKillContextMenu, -70 ;Delay to prevent race condition
}

TimerKillContextMenu:
	WinWait, ahk_group ContextMenus,, 0 ;0 is actually 0.5 seconds (as per AHK help file)
	IfWinExist , ahk_group ContextMenus ;Don't close last found window if no context menu found
		WinClose
Return

;A few example hotkeys

~RButton & LButton::
	KillContextMenu() ;First kill context menu if any, then do rest
	MsgBox You pressed RButton & LButton
Return

~LButton & RButton::
	MsgBox You pressed Lbutton & RButton
Return

~MButton & RButton::
	SendInput {Browser_Forward}
Return

RButton & MButton::
	KillContextMenu()
	SendInput {Browser_Back}
Return


Pulover
  • Guests
  • Last active:
  • Joined: --
I know this has been already solved, but I came to this thread while looking for solution to my problem and found it interesting. I found a way to solve my question a few time later and thought I could make this one work too with some hotkeys and if's (inspired, of course, by Nimda's Talking Script :lol: ).

Here it is in case anyone's interested. This method DOES NOT require AHK_L.

VolChange = 0  ;This variable will tell the script whether to send the RButton or not.
Hotkey, RButton, VolHK, On
Hotkey, ^, VolHKOff, On  ; Since the above hotkey makes RButton drag impossible, this one turns it off when you hold Control, or you can change it to something else.
return

VolHK:
Hotkey, WheelUp, VolUp, On
Hotkey, WheelDown, VolDn, On
KeyWait, RButton, U
Hotkey, WheelUp, VolUp, Off
Hotkey, WheelDown, VolDn, Off
If VolChange = 1
{
	VolChange = 0
	return
}
Else
If VolChange = 0
{
	Send {RButton}
}
return

VolUp:
Send {Volume_Up}
VolChange = 1
return

VolDn:
Send {Volume_Down}
VolChange = 1
return

VolHKOff:
Hotkey, RButton, VolHK, Off
KeyWait, ^, U
Hotkey, RButton, VolHK, On
return


Peaceteddie
  • Members
  • 1 posts
  • Last active: Aug 14 2013 11:10 PM
  • Joined: 12 May 2013

http://www.autohotke...e-with-rbutton/