Can you register keyPressed() or mousePressed() events outside of Processing?

edited November 2013 in How To...

I am trying to make a program that can count whether there has been activity on the computer - either keyboard activity or mouse activity. And as long as I am typing with the processing frame in the front, it is able to register the activity, but my thought was to register activity outside the processing frame as well. So if the processing app is running in the background and you type something in Word for instance, I would like to be able to register this activity. Is this possible?

This was my initial idea, but as I mentioned, it only register the activity when the frame is in focus.

int mouse = 0;
int keypress = 0;
int activity = 0;

int savedTime;
int totalTime = 60000;
int minutepassed = 0;
void setup(){
  size(500,500);
  background(255);


  savedTime = millis();

  }

void draw(){
  int passedTime = millis() - savedTime;
   if(passedTime>totalTime){
       minutepassed++;
    println( minutepassed + " minute(s) passed! ");
    printactivity();
    savedTime = millis();
    mouse=0;
    keypress = 0;
  }
}

void mousePressed(){
  mouse++;

}

void keyPressed(){
  keypress++;
}

void printactivity(){
 activity = mouse+keypress;
  println("mousepress = " + mouse);
  println("keypress = " + keypress);
 println("total activity = " + activity +"/min");
}

Answers

  • Maybe if you could make a glass pane over the screen? Would it then be possible to "control" the other programs while the glass pane is still registering the mouse and keyboard events?

Sign In or Register to comment.