Sample code to use mouse wheel events in Processing.

// mouseWheel.pde
// code to use mouse wheel in Processing

// must import java.awt.event.*
import java.awt.event.*;

float y;

void setup() {
  size(400,400);

  // add mouse wheel listener
  frame.addMouseWheelListener(new MouseWheelInput());

  y=height/2;
}

void draw() {
  background(100);
  ellipse(width/2, y, 50,50);
}

// convenience class to listen for MouseWheelEvent
// modify mouseWheelMoved() for your own purposes

class MouseWheelInput implements MouseWheelListener{

  void mouseWheelMoved(MouseWheelEvent e) {
    int step=e.getWheelRotation();
    y=y+step*5;
  }

}

There is one comment to "Code: mouseWheel.pde". You may leave your own comment.
1. Kyle McDonald, September 28th, 2007 at 16:09

Nice!

Comment on this entry

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>