PDA

View Full Version : Help to understand mouse.buttonStates


Fabiomussarela
12-19-2007, 05:18 PM
Hi everyone. I tried everything and still canīt make max return true for the "mouse.buttonStates"

I looked on old posts, but doesnt helped too much :(

whats wrong in this code ?

rollout xRol "rollout"
(

on xrol lButtonDown pos do
(
if mouse.buttonStates[1] == true do print "Left Button"
)

)
createDialog xRol 200 200




thanks

RustyKnight
12-19-2007, 10:39 PM
Hi everyone. I tried everything and still canīt make max return true for the "mouse.buttonStates"

I looked on old posts, but doesnt helped too much :(

whats wrong in this code ?

rollout xRol "rollout"
(

on xrol lButtonDown pos do
(
if mouse.buttonStates[1] == true do print "Left Button"
)

)
createDialog xRol 200 200




thanksHere is an incrediably stupid statement...

lButtonDown is an event that is fired, when the left mouse button is down...so, in theory, it should only ever be called when the left mouse button is down, right...so, why should you need to determine the button state?!?

It is possible that the lbuttondown event is been called BEFORE the mouse state is been updated, as the event MAY not have filtered down to the viewports...where I presume the mouse info is been handled...

Not having done any work in this area, I could be completly wrong of cause, BUT this problem occurs regularly in application developement, the mouse event been consumed by handler's higher up the container hierarcy...but you have the opposite effect...the event is been consumed or handled by the rollout, before it is been handled by the mouse tool's handler...

Just a thought

Fabiomussarela
12-19-2007, 11:09 PM
Hi RustyKnight, thanks for replying !! I know itīs a pointless code up here, it is just a way to show the problem.

hereīs a different aproach!
try this, create a new maxScript window, type

mouse.buttonStates[2]

hold your middle mouse buton and press CTRL + E to evaluate the code.

Even with just this line of code and with the mouse button pressed, max doesn return the correct value!
The same for the right mouse button.
:sad:

This kind of code works for the "keyboard.shiftpressed" and other keyboard commands.

EricDLegare
12-20-2007, 12:06 AM
Are you sure that "mouse.buttonStates" returns an array of booleans ? #(false,false,true) ?

Maybe it's returning an array of pressed buttons ? #(1,3) ?

Just a guess...

EricDLegare
12-20-2007, 12:25 AM
I had to check it out ^_^

So the problem is that "mouse.buttonStates" won't return an array of booleans,

Let's say if you are pressing the leftbutton, you will get #{1} instead of #(true,false,false)
Hope it helps ^_^

PEN
12-20-2007, 01:42 AM
Mouse.buttonStates returns a bit array.

#{} --no mouse button pressed
#{1} --Left button pressed
#{1..3} -- Left, middle and right buttons pressed
#{2..3} --Middle and right pressed.

You need to check what the values are and that will tell you what button is pressed.


rollout buttonTest "Button test"
(
timer timeIt ""

on timeIt ticked do
(
print mouse.buttonStates
)
)
createDialog buttonTest


Here is a couple of things to remember. First off it will only work in the viewport and not over another dialog. Second the right #{3} button can give odd results. Run the code above and right click to bring up the quad, don't click on the quad and just move your mouse off it and let go. It will continue to report that the right mouse button is down. I have no idea how to deal with that one. Is there a dotNetObject that can be used. I looked but couldn't get it to work with a quick test. "system.windows.input.mouse" was what I found but couldn't get it to work. I believe that it was dotNet 3, does Max handle that version?

Fabiomussarela
12-20-2007, 01:58 AM
Hi Paul and Eric, thanks for the replies :)

Yeah, my problem was that I need the mouse state over a dialog, unfortunatly max doesnīt handle this! I didnīt know that !

Well, thanks anyway! Letīs see if Iīll be able to handle some .net stuff :)

PEN
12-20-2007, 02:17 AM
Well createDialog handles it if you are looking to just get the mouse over a rollout.

RustyKnight
12-20-2007, 07:57 AM
I had to check it out ^_^

So the problem is that "mouse.buttonStates" won't return an array of booleans,

Let's say if you are pressing the leftbutton, you will get #{1} instead of #(true,false,false)
Hope it helps ^_^Actually, the sample given only returns #{} ... tried it :)

As pen has pointed out, it will only work on the viewport, so I would rely more on the actual event then I would the buttonStates

Shane

RustyKnight
12-20-2007, 08:13 AM
Mouse.buttonStates returns a bit array.

#{} --no mouse button pressed
#{1} --Left button pressed
#{1..3} -- Left, middle and right buttons pressed
#{2..3} --Middle and right pressed.

You need to check what the values are and that will tell you what button is pressed.


rollout buttonTest "Button test"
(
timer timeIt ""

on timeIt ticked do
(
print mouse.buttonStates
)
)
createDialog buttonTest


Here is a couple of things to remember. First off it will only work in the viewport and not over another dialog. Second the right #{3} button can give odd results. Run the code above and right click to bring up the quad, don't click on the quad and just move your mouse off it and let go. It will continue to report that the right mouse button is down. I have no idea how to deal with that one. Is there a dotNetObject that can be used. I looked but couldn't get it to work with a quick test. "system.windows.input.mouse" was what I found but couldn't get it to work. I believe that it was dotNet 3, does Max handle that version?Max should handle dotnet 3, it shouldn't really care, so long as what you are accessing is avaliable within the library.

The immediate issue I see is how do we construct a DependencyObject and MouseHandler!? I don't think this functionality exists within max at this time...but I could be wrong...

Shane

ypuech
12-20-2007, 11:01 AM
Max should handle dotnet 3, it shouldn't really care, so long as what you are accessing is avaliable within the library.
Max (even 2008) doesn't handle .NET Framework 3 and the presentation framework (System.Windows.Input.Mouse is WPF).
I used WPF (in fact a .NET 3.0 Forms embedding a WPF button used in a Utility plugin dialog) in a C++ plugin but no way to use it in MAXScript as the .NET bridge needs to handle all the new data and classes (and needs some general improvements of course ; arrays for example).

PEN
12-20-2007, 02:00 PM
So anything .net 3 is not supported then? That bites.

ypuech
12-20-2007, 04:46 PM
So anything .net 3 is not supported then? That bites.
In fact, most of the times you can access the classes of .NET 3.
But you can't use them because for example dotNet bridge was designed for .NET Forms, not WPF Controls, so Presentation Framework mechanisms cannot be used and understand in MAXScript.

RustyKnight
12-20-2007, 10:34 PM
In fact, most of the times you can access the classes of .NET 3.
But you can't use them because for example dotNet bridge was designed for .NET Forms, not WPF Controls, so Presentation Framework mechanisms cannot be used and understand in MAXScript.That sounds better...I though max was using a form of reflection to create the underlying dotnet classes through maxscript, so it would stand to reason that it would capable of supporting dotnet 3...but of course there was always going to be limitations...

Shane

ypuech
12-20-2007, 11:24 PM
That sounds better...I though max was using a form of reflection to create the underlying dotnet classes through maxscript, so it would stand to reason that it would capable of supporting dotnet 3...but of course there was always going to be limitations...
The dotNet bridge was developed by Larry Minton. It's not a form of reflection but a real wrapper. You can look at the sources at maxsdk\samples\maxscript\mxsdotNet. The code is a mix of unmanaged/managed code: C++ and C++/CLI. So it's not easy to read it and understand it.

CGTalk Moderation
12-20-2007, 11:24 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.