What is "event" in mousePressed(event) seen in reference

_vk_vk
edited February 2014 in Programming Questions

Just curious, I have seen this form mousePressed(event) in the reference. What would be event in this use? thanks

Tagged:

Answers

  • edited February 2014

    I guess that is very similar to mouseWheel(), which doesn't have a no parameter overloaded form:

    http://processing.org/reference/mouseWheel_.html

  • Answer ✓

    Most of the event handling methods have two signatures, one without a parameter and one with a single processing.event.Event class parameter.

    The code below shows both forms, you can use either one (but not both together). The advantage of using method signature 2 is that the Event object has additional methods that you can call e.g. event.isShiftDown() returns true if the shift key is being held down when the mouse button is pressed.

    In the code below only method 2 is being called and method 1 is ignored, as I said use one or the other.

    void setup() {
    }
    void draw() {
    }
    
    // Method signature 1
    void mousePressed() {
      println("EVENT ");
    } 
    
    // Method signature 2
    void mousePressed(MouseEvent event) {
      println("EVENT " + event);
    }
    

    To find out what other methods are available then look at the source code for Event, MouseEvent and KeyEvent

  • Well, good to know : ) Thanks!

Sign In or Register to comment.