[SOLVED * Lexikos]Right mouse combo problem: context menu, one ór the other

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
RUBn
Posts: 51
Joined: 27 Nov 2013, 05:12
Contact:

[SOLVED * Lexikos]Right mouse combo problem: context menu, one ór the other

18 Aug 2015, 14:42

I want to do some combos with my right mouse as I find it very handy. Unfortunately, I always bump in the one or other problem and it's above my head again.
Let me start with the script:

Code: Select all

XButton1 & RButton::			;	<-- Close tab/document or program
   MouseGetPos,,,Winid, ControlClass
   WinActivate, ahk_id %Winid%   
   KeyWait RButton	;only on release, so we can still cancel
   if getKeyState("Alt","P")
      WinClose, ahk_id %Winid%;,,1 ; 1 seconds wait, allow cancel
   else 
	;Traytip,, ^w
      Send ^w	
   KeyWait XButton1    ; Please no Browser_Back afterwards
   return
 
RButton & WheelUp::Send {PgUp}
RButton & WheelDown::Send {PgDn}
RButton::RButton ; restore the original RButton function = release without others, do normal
The one or the other:
  • As is, the XButton1 & RButton doesn't work on some programs, because the context menu is poping up, and then the ^w is sent to the contextmenu, not to the program
  • If I remove the RButton::RButton, it works again, but then I have no context menu, ever, but I want it when no other things are pressed down
I find it weird nonetheless as AHK should know in XButton1 & RButton that the RButton was not pressed alone and no contextmenu should be shown, and since there s no tilda before RButton::RButton, it shouldn't fire, but then again, all these special cases in windows key handling drive me crazy.

Thanks for some insight :-)
Last edited by RUBn on 19 Aug 2015, 11:21, edited 1 time in total.

I am also: Image-motiv for professional, volunteer & open source (web) development
lexikos
Posts: 9589
Joined: 30 Sep 2013, 04:07
Contact:

Re: Right mouse combo problem: context menu, one ór the other

18 Aug 2015, 18:42

This script has the same behaviour:

Code: Select all

XButton1 & RButton::MsgBox XButton1 & RButton
RButton Up::MsgBox RButton up
Defining a custom combination changes the behaviour of the prefix key (XButton1), not the suffix key (RButton).

If you call ListHotkeys, you will see two hotkeys that aren't explicitly written in your script:

Code: Select all

*RButton
*RButton up
Because...
When a script is launched, each remapping is translated into a pair of hotkeys.
Source: Remapping Keys and Buttons
Since you have also used RButton as a prefix key in a custom combination, when you release the button, one RButton hotkey and one RButton up hotkey will fire. If you're holding XButton1, then XButton1 & RButton will fire. So what you end up with is only one half of the remapping, equivalent to Send {RButton up}, which still causes a context menu to pop up.

The easiest way to avoid this problem is to define both halves of the hotkey:

Code: Select all

XButton1 & RButton::
   ;...
   return
XButton1 & RButton Up::return
User avatar
RUBn
Posts: 51
Joined: 27 Nov 2013, 05:12
Contact:

Re: Right mouse combo problem: context menu, one ór the other

19 Aug 2015, 11:13

I see. Thank you very much, Lexikos.
I've learned something basic here, I think.

It would have been impossible for me to think this out logically without knowing this AHK logic fact. TBH, I never will be good at this, having too many IT projects in different programming languages and standards. And I'm sure you or someone pointed this out somewhere on this forum, but I guess you had to know the right keywords to begin with...

Respect! ;-)

I am also: Image-motiv for professional, volunteer & open source (web) development

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mankvl, OrangeCat, sanmaodo, zerox and 311 guests