'keyEvent' in PApplet registerMethod (similarly to mouseEvent)

hello, is there a quick trick to register a "keyEvent" method in processing applet so i could register keyboard handling in any of my classes?

As far as i know we can register "draw", "pre", "post" and "mouseEvent" , keyboard input would also be helpful! If it's not currently supported, is there any quick tweak inside PApplet class to do it? I find method registering very useful :)

thanks for feedback

Answers

  • keyPressed, keyTyped, keyReleased.....

    see reference

  • edited June 2014 Answer ✓

    I guess you've meant registerMethod(), right? ;)
    Dunno how you've reached the conclusion that "mouseEvent" is recognized, but not "keyEvent"?! :-/

    Just take a look at registerMethod() inside class PApplet itself:

    https://github.com/processing/processing/blob/master/core/src/processing/core/PApplet.java#L1342

    public void registerMethod(String methodName, Object target) {
      if (methodName.equals("mouseEvent")) {
        registerWithArgs("mouseEvent", target, new Class[] { processing.event.MouseEvent.class });
    
      } else if (methodName.equals("keyEvent")) {
        registerWithArgs("keyEvent", target, new Class[] { processing.event.KeyEvent.class });
    
      } else if (methodName.equals("touchEvent")) {
        registerWithArgs("touchEvent", target, new Class[] { processing.event.TouchEvent.class });
    
      } else {
        registerNoArgs(methodName, target);
      }
    }
    
Sign In or Register to comment.