We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › MouseWheelListener
Page Index Toggle Pages: 1
MouseWheelListener (Read 1451 times)
MouseWheelListener
Nov 12th, 2009, 9:52am
 
Hi i´m doing my first processing project.

i try to build a sketch of a video playback controlled speed by the mousewheel, so if the user spin faster the video play faster and if dont spin the video pause....  Roll Eyes

So i need to check when the user stop spining the mousewheel, i search and find how to implement a listener to get the speed but i dont see any event like onStopMoving or somethig like that.

How can i know when the mousewheel stop spining ??????

Thanks in advance
Re: MouseWheelListener
Reply #1 - Nov 12th, 2009, 10:08am
 
See MouseEvent > MOUSE_WHEEL.

When that event isn't being triggered the mouse wheel isn't moving Wink

If you need help implementing MouseEvent in Processing do a search of the forum - I've certainly posted examples; though I haven't used MOUSE_WHEEL it should be pretty straightforward...
Re: MouseWheelListener
Reply #2 - Nov 12th, 2009, 10:21am
 
blindfish

Thanks for your fast reply, i will try it.

Its so obvious that im feeling embarassed....
Re: MouseWheelListener
Reply #3 - Nov 13th, 2009, 5:05am
 
i did this skecth, i use a boolean var to indicate if the mousewheel is spining or not.

So in setup() set the var value to false and when the mousewheel event is tiggered the var value is set to true.

But how can i do to reset the var value to false when i stop spining the mousewheel. Can someone give me a clue about that, im sure that its a simple task but i can even imagine how to do.......  Tongue



boolean funciona;


void setup() {
 size(960, 540, P2D);
 background(0);
 funciona=false;
 addMouseWheelListener(new java.awt.event.MouseWheelListener() {
   public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) {
   funciona = true;
 }});
}


void draw()
{
println(funciona);
}
Re: MouseWheelListener
Reply #4 - Nov 13th, 2009, 5:44am
 
Actually after posting that link it occurred to me that this issue might be a problem.  I was just looking at one possible workaround which involves registering mouse events with Processing - something Quark posted a while ago and that I've found useful for dealing with mouse events in classes...  However it doesn't appear to work with Mouse wheel events - though it  may be that I've made a mistake in the implementation here:

Code:
boolean funciona;


void setup() {
size(960, 540, P2D);
background(0);
funciona=false;

// Presumably when you're not registering the event with a class you just register it with 'this'...
registerMouseEvent(this);

}


void draw() {
if(funciona) {
println("mouse wheel event");
}

}

void mouseEvent(MouseEvent event){
 switch(event.getID()) {
  // For test purposes - this works
  //case MouseEvent.MOUSE_PRESSED:
  //  println("pressed");
  //break;
 
  // but this doesn't :(
  case MouseEvent.MOUSE_WHEEL:
    println("wheelmoved");
    funciona = true;
  break;
 
 // I figured if you were only checking for mouseWheel events in this switch() you could simply use default to set funciona back to false...
 default:
   funciona = false;
 break;
 }
}


Hopefully someone better placed than I can offer a suitable solution Wink
Re: MouseWheelListener
Reply #5 - Nov 13th, 2009, 6:15am
 
MOUSE_WHEEL is nowhere in Processing's core sources. Even "wheel" is found once, in "color wheel"... Smiley
Re: MouseWheelListener
Reply #6 - Nov 13th, 2009, 6:17am
 
Sad
I'd assumed that behaviour was inherited from Java.  Are there issues with using AWT in Processing?
Re: MouseWheelListener
Reply #7 - Nov 13th, 2009, 7:07am
 
So it appears to be a big problem Cry

what im trying to do its to use a treadmill to simule a virtual jogging, i thinked to use the mousewheel of the mouse to get the(runing speed), but maybe i try to put the mouse in the bottom.... What do you think?

i can chek if the mouse is moving and the speed


Thaaaaanks for your help
Re: MouseWheelListener
Reply #8 - Nov 13th, 2009, 7:45am
 
When you say treadmill you mean in real physical space  So you wanted to physically attach the mousewheel to the treadmill to get its speed  That's awesome and Heath Robinson would be impressed Cheesy

I guess you could use the mouse in the alternative way you describe...  Otherwise you might want to look at using something like Arduino to use as an interface to some real world sensors.  It's got plenty of inputs so you could potentially attach some more accurate speed measuring sensors as well as heart-rate sensors etc. and feed them all into Processing...
Re: MouseWheelListener
Reply #9 - Nov 13th, 2009, 7:57am
 
Yes, a real treadmill and a 8mX4m semispheric screen in front. So if you run the video play and seems like runing... Cheesy

Arduino seems the "professsional way to do that"  maybe i can use a rotary sensor (like the one that its in a mousewheel).

For the video part im using the JMCvideo library.... any advice or recomendation about that.
Page Index Toggle Pages: 1