Ignoring more than two keyPresses
in
Programming Questions
•
1 years ago
I'm using booleans to track which keys are pressed. I had thought that this was the fix for multiple keypresses but am now finding that only the first two are tracked. Any additional keys are ignored. Furthermore, key releases are ignored until those additional keys are released also. How can I allow any number of keys to be pressed?
Maybe I'm just missing something in the code. It's probably worth noting that right and left are changing angle of rotation while up and down are moving forward and backward along that angle. It's not just a matter of:
{ right = x++; left = x--; up = y--; down = y++; }
Any thoughts?
- void keyPressed(){
- if(key == CODED){
- switch(keyCode){
- case UP:
- up = true;
- break;
- case DOWN:
- down = true;
- break;
- case LEFT:
- left = true;
- break;
- case RIGHT:
- right = true;
- break;
- }
- }
- }
- void keyReleased(){
- if(key == CODED){
- switch(keyCode){
- case UP:
- up = false;
- break;
- case DOWN:
- down = false;
- break;
- case LEFT:
- left = false;
- break;
- case RIGHT:
- right = false;
- break;
- }
- }
- }
1