We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi!
One of my friends wrote a small code - a car mooving through traffic - and has the following issue: simultaneous key presses are not resolved individually at times, especially when playwers start mashing the buttons.
What is the right way of dealing with multiple keyboard presses?
This is the code: https://www.openprocessing.org/sketch/396736
Answers
I have found a couple of solutions. Most of them involve setting up an array to store the buttons.
Most keyboards can only read about a maximum of 5 simultaneous key input at once, anything more than that, it's mechanically not wired to read the additional key presses. I'm not sure that is your problem though as you might need to do some trial and error test to find out exactly when the key presses are not being registered.
And the biggest problem occurs if two keys are pressed in the same frame. In that case, you just can't detect multiple key presses.
However, since this is a game, you can wire up some gaming keyboard or something that can detect multiple key presses.