how to use the mousewheel in processing

Nikolaus Gradwohl2010-08-01T20:16:38+00:00

Mouse-events like move, drag or click are very simple to implement in processing. Only the mouse-wheel needs some special handling.

To get the mouseWheel events in processing the sketch needs to register a mouseWheelListener int the setup method

void setup() {
  size(300,300);
  smooth();
  addMouseWheelListener(new java.awt.event.MouseWheelListener() { 
    public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) { 
      mouseWheel(evt.getWheelRotation());
  }}); 
}

and then a handler function that gets called by the listener every time the mousewheel is triggered

void mouseWheel(int delta) {
}

The value of delta indicates the direction and the speed by which that scroll-wheel has been turned.

Click here to see an applet that implements the callback function and zooms some rects.

Tweet This! submit to reddit Digg! Tags: | 1 comments | no trackbacks

See also:

sketch experiment 7 - osc events
nested cubes in processing
processing phaseflower
Time Perception
de jong attractor

Trackbacks

Comments

Leave a response

  1. srinidhi nakshatri 2012-12-19T08:19:29+00:00

    How can we insert jre lib in processing because you are using java.awt.event.MouseWheelListener

Leave a comment