In debug mode how can I test keyPressed or mousePressed

I can't figure out how to use keyPressed in debug mode - the cursor focus is on the processing editor and I just end up modifying the sketch.

Answers

  • Basically keyboard and mouse events have a complex method of execution, so it may not even be possible.

  • edited January 2017 Answer ✓

    @Jackieh111 --

    When I run a sketch in debug mode, I need to:

    1. Click on the Debug icon
    2. Run the sketch
    3. Click on the sketch window once to give it mouse focus
    4. Wait an extra 2-3 seconds for event startup (especially with text)
    5. Expect that there might be slow / mushy interaction speed -- perhaps due to added overhead of running in debug?

    However, both keyPressed and mousePressed do work correctly in debug mode. Here is a test sketch running at 10 fps:

    void setup(){
      fill(0);
      frameRate(10);
    }
    void draw(){
      background(255);
      translate(width/2,height/2);
      if(keyPressed){
        text(key,0,0);
        println(key, millis());
      }
      if(mousePressed){
        rect(-10,-10,20,20);
        println("*", millis());
      }
    }
    

    ...and when I launch it in debug mode, click in the window, and then slowly type "qwerty" and click the mouse, checks for keyPressed and mousePressed work correctly, and I see letters and images drawn to the screen and get this console output:

    q 3338
    w 4643
    e 6143
    r 6942
    t 7745
    y 8545
    * 11944
    
  • Oh. You meant the variables.
    I thought the question was about the functions.

  • Thanks @jeremydouglass - I will try that out. Thanks for your help.

Sign In or Register to comment.