Key Just Pressed?
I don't want to reveal what I'm working on, so here is a basic example to understand my problem.
In this example, I have a simple counter that goes up when you press a key.
var counter = 0;
function setup() {
textSize(40);
}
keyPressed = function() {
counter += 1;
background(255,255,255);
fill(255, 0, 0);
text(counter, 0, 50);
};
When you paste this code in a Khan Academy project, the counter will go up at the same speed as holding down a letter. It's tied to the users OS key delay rate.
When you paste this code in the official ProcessingJS editor, it will only press once, and you have to RELEASE and PRESS the key AGAIN to make the counter go up.
I want to achieve what the ProcessingJS editor does: call the action as soon as the key has just been pressed, and don't call it repeatedly.
Please sign in to leave a comment.