Running a Program in the Background w/ Input
in
Programming Questions
•
4 months ago
The first project I've tackled with Processing was making a sketch that tracks your keyboard movements from key to key, and how many times you use a key. I was inspired by the
IOGraph Mouse Tracker, and I want to make it act the same way. I want to allow the user to work on, say, an essay for school, but track all the input with this program to generate the image, which looks something like this:
It's pretty self-explanatory, but the darker the key, the more you hit the key, and the lines track the transition from one key to another (once again the darker to more often it's made).
Here's the code:
- PVector current = new PVector(0,0);
- PVector previous = new PVector(0,0);
- float r = 14;
- int keyTotal = 26;
- PVector keyboardSize = new PVector(330,150);
- int[][] keyLocation = {{40,60},{170,90},{110,90},{100,60},{90,30},{130,60},{160,60},{190,60},{240,30},{220,60},{250,60},{280,60},{230,90},{200,90},{270,30},{300,30},{30,30},{120,30},{70,60},{150,30},{210,30},{140,90},{60,30},{80,90},{180,30},{50,90}};
- void setup() {
- // size(660,300);
- size(displayWidth,displayHeight);
- background(255);
- noStroke();
- noFill();
- rectMode(RADIUS);
- // for (int i = 0; i < keyTotal; i++) {
- // rect((keyLocation[i][0]/keyboardSize.x)*width,(keyLocation[i][1]/keyboardSize.y)*height,(r/keyboardSize.x)*width,(r/keyboardSize.y)*height);
- //}
- fill(0,0,0,3);
- }
- void draw() {
- if (keyPressed) {
- if (key == 49) {
- saveFrame("keyboard-###.png");
- }
- if (key == 32) {
- current.x = 170;
- current.y = 120;
- } else if (key >=97 && key <=122) {
- previous.x = current.x;
- previous.y = current.y;
- current.x = keyLocation[key-97][0];
- current.y = keyLocation[key-97][1];
- } else {
- previous.x = 0;
- previous.y = 0;
- }
- if (previous.x != 0) {
- stroke(0,0,0,5);
- line((current.x/keyboardSize.x)*width,(current.y/keyboardSize.y)*height,(previous.x/keyboardSize.x)*width,(previous.y/keyboardSize.y)*height);
- noStroke();
- rect((current.x/keyboardSize.x)*width,(current.y/keyboardSize.y)*height,(r/keyboardSize.x)*width,(r/keyboardSize.y)*height);
- }
- }
- }
So what do you say? Is what I'm hoping for a possibility with Processing? I really hope so
1