// This implements a simple typewriter.
// Stores the characters that were typed
char textLine[] = {};
// This keeps track of whether the key was pressed on the
// last frame. I am using it to make sure that we only
// store a new key on the first frame after it has been pressed.
boolean wasPressed = false;
int charWidth = 11;
void setup() {
size(800, 100);
background(0);
fill(255);
}
void draw() {
if (keyPressed && !wasPressed) {
// check if an alphabetical key was pressed
if(((key >= 'a') && (key <= 'z')) ||
((key >= 'A') && (key <= 'Z'))) {
// FILL IN THIS LINE TO STORE THE KEY
}
}
// This draws the keys to the screen
background(0);
for(int i = 0; i < textLine.length; i++) {
text(textLine[i],i*charWidth,height/2);
}
// remember whether the key was pressed
wasPressed = keyPressed;
}