keyPressed() needs some clarification.
in
Programming Questions
•
10 months ago
In the documentation for KeyPressed() it should be explicitly noted that it is only called synchronously with draw. Not asynchronously.
- timer time;
void setup()
{
time = new timer();
size(90,90,P3D);
}
void draw()
{
frameRate(0.5);
background(255);
}
void keyPressed()
{
time.Turn();
//print(keyCode);
}
class timer
{
private int time;
private boolean tim;
private int downtime;
public timer()
{
tim = false;
}
public int Turn()
{
if (tim == false)
{
time = millis();
tim = true;
return 0;
}
else
{
downtime = millis();
tim = false;
println(downtime - time);
return downtime - time;
}
}
}
Example output:
- 2003
0
1996
1999
0
0
0
2001
4000
4000
This code, if Keypressed() was asynchronous, would print values of an exact nature. However as KeyPressed() is only synchronous it only prints values similar to 2000 as that is the set framerate. It should be stated on the KeyPressed() site that it is synchronous, or, better still, it be made asynchronous to allow for more exact and responsive key presses (a very usefull, and uncommon, feature for games).
On the other hand if there is an asynchronous Keypressed() function could you inform me how to create or use it.
On the other hand if there is an asynchronous Keypressed() function could you inform me how to create or use it.
1