Notifications
Clear all

[Closed] Help to understand mouse.buttonStates

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

14 Replies

Here 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

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.
🙁

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

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…

I had to check it out

So the problem is that “mouse.buttonStates” won’t return an array of booleans,

[size=2]Let’s say if you are pressing the leftbutton, you will get [size=1][size=2][color=white]#{1} instead of #(true,false,false)
[/color][/size][/size][/size]Hope it helps

 PEN

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?

2 Replies
(@rustyknight)
Joined: 11 months ago

Posts: 0

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)
Joined: 11 months ago

Posts: 0

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).

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

Well createDialog handles it if you are looking to just get the mouse over a rollout.

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

 PEN

So anything .net 3 is not supported then? That bites.

3 Replies
(@ypuech)
Joined: 11 months ago

Posts: 0

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)
Joined: 11 months ago

Posts: 0

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)
Joined: 11 months ago

Posts: 0

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.