xxxxxxxxxx
//https://github.com/processing/processing/issues/4952
//after a long press the Pressed or Typed events don't fire
//it's a new mac problem. There's a fix in terminal:
// defaults write -g ApplePressAndHoldEnabled -bool false
boolean iTyped = false; // all these booleans are false in the begining since we want to activate them on interaction
boolean aTyped = false;
boolean wTyped = false;
boolean oTyped = false;
boolean leftTyped = false;
void setup() {
size (200, 200);
}
void draw() {
background(100, 100, 234);
// guide lines so we can see the edge of the screen
line (0, 0, 0, height);
line (width-1, 0, width-1, height);
line (0, 0, width, 0);
line (0, height-1, width, height-1);
if (iTyped) {
background(240, 10, 100);
}
if (aTyped) {
strokeWeight(1);
fill (255, 255, 0);
ellipse (width/2, height/2, 50, 50);
}
if (wTyped) {
fill (0, 255, 255);
rect (10, 10, 30, 30);
}
if (oTyped) {
strokeWeight(4);
line ( (width*3/4), (height - 50), (width - 10), (height - 10) );
line ( (width - 10), (height - 50), (width*3/4), (height - 10) );
}
if (leftTyped) {
strokeWeight(1);
fill (255, 255, 0);
rect ( (width-40), 10, 30, 30);
}
text ("Press: A | I | W | O | Left Arrow", 10, height/2);
}
void keyPressed() {
// char is ' ' while strings are " "
// a string has more alphabets so it has two ;) - ben
if (key == 'i') {
iTyped = true;
}
if (key == 'a') {
aTyped = true;
}
if (key == 'w') {
wTyped = true;
}
if (key == 'o') {
oTyped = true;
}
// "Reserved Variables" to use arrow keys, and special non-letter keys UP, DOWN, LEFT, and RIGHT as well as ALT, CONTROL, and SHIFT
if (keyCode == LEFT){
leftTyped = true;
}
}
void keyReleased() {
if (key == 'i') {
iTyped = false;
}
if (key == 'a') {
aTyped = false;
}
if (key == 'w') {
wTyped = false;
}
if (key == 'o'){
oTyped = false;
}
if (keyCode == LEFT){
leftTyped = false;
}
}