Detect right-click?
tkessler
SetWindow kwTopWin hook=TableHook, hookevents=1 // mouse down events
Function TableHook(infoStr)
String infoStr
String event= StringByKey("EVENT",infoStr)
Print "EVENT= ",event
strswitch(event)
case "mousedown":
Variable xpix= NumberByKey("MOUSEX",infoStr)
Variable ypix= NumberByKey("MOUSEY",infoStr)
PopupContextualMenu/C=(xpix, ypix) "yes;no;maybe;"
strswitch(S_selection)
case "yes":
// do something because "yes" was chosen
break;
case "no":
break;
case "maybe":
// do something because "maybe" was chosen
break;
endswitch
endswitch
return 0
End
Function TableHook(infoStr)
String infoStr
String event= StringByKey("EVENT",infoStr)
Print "EVENT= ",event
strswitch(event)
case "mousedown":
Variable xpix= NumberByKey("MOUSEX",infoStr)
Variable ypix= NumberByKey("MOUSEY",infoStr)
PopupContextualMenu/C=(xpix, ypix) "yes;no;maybe;"
strswitch(S_selection)
case "yes":
// do something because "yes" was chosen
break;
case "no":
break;
case "maybe":
// do something because "maybe" was chosen
break;
endswitch
endswitch
return 0
End
I'd like to modify it to detect a right-click so the system only shows the contextual menu when issuing a left-click, and not when invoking the right-click.
On the same note, would there be a similar way to detect other mouse clicks (ie, middle-click, or 4th and 5th buttons)? The goal ultimately would be to sequester various functions to different contextual menus invoked by different mouse clicks. I know you can use the system modifier keys using the "getkeystate" function to invoke different menus, but would prefer to have this done via mouse buttons if possible.
bit 0: Mouse button is down.
bit 1: Shift key is down.
bit 2: Option (Macintosh ) or Alt (Windows ) is down.
bit 3: Command (Macintosh ) or Ctrl (Windows ) is down.
bit 4: Contextual menu click: right-click or Control-click (Macintosh , or right-click (Windows ).
So, start with something like:
The other mouse buttons aren't checked or reported, sorry!
--Jim Prouty
Software Engineer, WaveMetrics, Inc.
January 20, 2013 at 08:04 am - Permalink
Function TableHook(s)
STRUCT WMWinHookStruct &s
Variable HookEvent = 0 // tells, if event was used
switch(s.EventCode)
case 3: // equals "mousedown"
If (s.EventMod == 16) // looking for a right click (bit 4) => right click menu
HookEvent = 1 // event used
PopupContextualMenu/C=(s.MouseLoc.h, s.MouseLoc.v) "yes;no;maybe;"
strswitch(S_selection)
case "yes":
// do something because "yes" was chosen
break;
case "no":
break;
case "maybe":
// do something because "maybe" was chosen
break;
endswitch
endswitch
return HookEvent
End
January 20, 2013 at 08:37 am - Permalink
January 20, 2013 at 08:45 am - Permalink
I am curious how a mouse has middle, 4th, and 5th buttons?
In any case, those "buttons" must send specific code sequences to distinguish them from each other, since they are otherwise just "clicks" to the system. It would seem then that capturing the specific code sequence corresponding to the specific button is what you want to do here.
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
January 21, 2013 at 08:13 am - Permalink
Many mice have more than the standard left and right clicks. In most scroll mice you can depress the scroll wheel as a 3rd click, and then others yet have side buttons and other inputs that can be assigned to many programs. Most generic drivers in operating systems recognize these button presses so applications should be able to make use of them rather easily.
Unfortunately it sounds like Igor currently only accepts the first two mouse inputs from the driver and isnt yet built to configure additional inputs.
January 21, 2013 at 09:23 am - Permalink
Well yes. After sending my reply, I realized that my Kensington track ball with four buttons, a scroll ball, and a scroll wheel must fit that model somehow. :-/
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
January 21, 2013 at 11:08 am - Permalink