I am keen to make use of the new event handling mechanism for libraries provided in V2.0b2. I know that there is documentation to come and perhaps I am being a bit hasty but I decided to do some experiments for my own benefit.
In the code below I have succeded in creating an object that handles mouse events with the current mouse position being updated all the time. It does not appear to be capturing key events. I am probably doing something wrong but I can't see it - must be tunnel vision.
This code was created in Eclipse
In the code below I have succeded in creating an object that handles mouse events with the current mouse position being updated all the time. It does not appear to be capturing key events. I am probably doing something wrong but I can't see it - must be tunnel vision.
This code was created in Eclipse
- import processing.core.PApplet;
- import processing.event.KeyEvent;
- import processing.event.MouseEvent;
- public class Test01 extends PApplet {
- EventHandler eh;
- public void setup(){
- size(300,300);
- eh = new EventHandler();
- registerMethod("keyEvent", eh);
- registerMethod("mouseEvent", eh);
- }
- public void draw(){
- background(255);
- fill(0);
- text(eh.mx + " " +eh.my, 10, 10);
- text(eh.keyChar, 10, 30);
- text(key, 10, 50);
- }
- public class EventHandler {
- public int mx, my;
- public char keyChar = '?';
- public void keyEvent(KeyEvent e){
- println("==========================================");
- println("\tTime = " + e.getMillis());
- println("\tAction = " + e.getAction());
- println("\tKeyCode = " + e.getKeyCode());
- println("\tKey = " + e.getKey());
- println("\tModifiers = " + e.getModifiers());
- keyChar = e.getKey();
- }
- public void mouseEvent(MouseEvent e){
- mx = e.getX();
- my = e.getY();
- }
- }
- }
1