Help to understand mouse.buttonStates

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  12 December 2007
Unhappy 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
__________________
__________________________________________
Keep on MAXing in the free world.

http://fabiomussa.blogspot.com/

 
  12 December 2007
Originally Posted by Fabiomussarela: 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
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
__________________
If it's worth doing, it's worth scripting
Don't wish for this to be eaiser, wish for you to better
 
  12 December 2007
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.
__________________
__________________________________________
Keep on MAXing in the free world.

http://fabiomussa.blogspot.com/


Last edited by Fabiomussarela : 12 December 2007 at 11:16 PM.
 
  12 December 2007
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...
__________________
EulerRnD.com

Last edited by EricDLegare : 12 December 2007 at 12:09 AM.
 
  12 December 2007
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 ^_^
__________________
EulerRnD.com
 
  12 December 2007
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?
__________________
Paul Neale
http://paulneale.com
 
  12 December 2007
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
__________________
__________________________________________
Keep on MAXing in the free world.

http://fabiomussa.blogspot.com/

 
  12 December 2007
Well createDialog handles it if you are looking to just get the mouse over a rollout.
__________________
Paul Neale
http://paulneale.com
 
  12 December 2007
Originally Posted by EricDLegare: 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
__________________
If it's worth doing, it's worth scripting
Don't wish for this to be eaiser, wish for you to better
 
  12 December 2007
Originally Posted by 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?
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
__________________
If it's worth doing, it's worth scripting
Don't wish for this to be eaiser, wish for you to better
 
  12 December 2007
Originally Posted by RustyKnight: 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).
__________________
 
  12 December 2007
So anything .net 3 is not supported then? That bites.
__________________
Paul Neale
http://paulneale.com
 
  12 December 2007
Originally Posted by PEN: 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.
__________________
 
  12 December 2007
Originally Posted by ypuech: 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
__________________
If it's worth doing, it's worth scripting
Don't wish for this to be eaiser, wish for you to better
 
  12 December 2007
Originally Posted by RustyKnight: 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.
__________________
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright Đ2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 12:36 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.