Detect which mouse button was pressed
Hi,
I'm new at Max so this may be a basic question, but I failed to find an answer in the forums or tutorials:
- How do you detected which mouse button was pressed? [mousestate] seems to only indicate that a button was pressed but not which one.
thanks,
jorge
Look at [modifiers] and combine the result with your [mousestate] to determine if the button was left-click or right-click.
Hmm, [modifiers] doesn't seem to change when I press any mouse button.
Also, when I press the right button a context-menu pops up.
I'd like to be able to know which mouse button a user pressed inside a video window. (I'm on a PC)
[modifiers] help file, with the patch locked. Just ignore the context menu :)
The jit.pwindow also reports mouse activity, check the help file for that too. In that case you might not need modifiers/mousestate.
[modifiers] only reports *keyboard* state. [jit.pwindow] reports mouse activity like [mousestate]. It doesn't report *which* mouse button was pressed.
Thanks anyway...
Discovered a couple things while looking at this, as always... interesting behaviors for the different clicks. Looks like any empty spot in a patch, or on some non-interactive objects like comment and panel, you'll get the context menu with the right-click. to avoid it you can use a [ubutton] over the whole patch, at the bottom layer.
pwindow doesn't give the context menu, which is nice... so just use the toggle from [modifiers] to check for right-click, and the toggle from [mousestate] or the pwindow to check when it's released:
Thanks!
I had missed that "Win Right Click" comment.
You can use the hi object to figure out exactly which mouse button was pressed (if you're looking for more than just left/right). Just tell it to focus on your mouse by name, and then poll it.
Also, different mice seem to have different protocols - on my two mice, the three buttons (elements 3/4/5) match, but my Macally reports x/y movement as 7/8 and scroll as 9, whereas my Logitech reports x/y as 6/7 and scroll as 8. If anyone has other brands lying around to test, I'd be curious to know whether either (or neither) is more standard.
I like your ubutton hack though - I've been trying to figure out a way to disable the right-click menu.
Definitely put the ubutton in the background and lock the background, if you're using it on the whole patch and are still developing.
I was thinking, the right-click detection plus the mouse coordinates could be a nice alternative to the built-in commands for jit.handle. So you could make the right-click do something different than the left-click, like maybe move the object instead of rotate. Would take just a bit of gating and substitution with jit.handle's output, and it would eliminate using either the option or the command key for one kind of interaction, which speeds things along. Now if the [hi] can detect the scroll wheel, you could also use that for the camera Z position, which would be the best...
Hi pseudostereo,
I tried the [hi] object but I can't get it to recognize my mouse.
I tried to tell it to focus by name but I don't know which name to use. I tried "Macally" on a Macally mouse and "HP" on an HP mouse but no joy. I also tried to look for clues on the Device Manager but also no joy.
[hi] outputs always a "[name] is not a valid device name".
None of my devices (mouse or keyboard) shows up in the [hi] device menu.
Any advice?
Thanks
what [modifiers] outputs will of course always depend on the mouse settings.
hi jorge -
when you send the message 'menu' to hi, it's supposed to send a list of available devices out its right outlet - if that isn't happening then something is wrong. Does anything at all show up in the device menu?
No, nothing shows up. I tried on two different (PC/Windows XP) computers.
I'll try to get hold of a gaming pad and see if that shows up, but my keyboard and mice don't...
I've noticed that some mice and keyboards won't show up, not sure of the official list, maybe they're just "too standard" or whatever. Gaming pads/joysticks have always worked for me.
Anyone know if [hi] keeps getting updated for new devices? I really want Max to be able to read from the Emotiv headset... I mean, who WOULDN'T want to control patches with their brain??
Looks like you can have it spit out keystrokes, which is a good start, but getting the raw "EEG-like" data as streams would be much cooler...