I want to control my Arduino Uno using my PC through a serial connection through USB. I want to control it using Processing. The Arduino is the brain of my robot and I want to control the motors of the robot using my arrow keys on my PC or WASD. Questions like this do already exist on this forum, but nowhere is written the case when you want to press two keys (for example W and A [FORWARD and LEFT]) simultaneously so that the robot will turn slightly left, but he will do this while going forward. Any help with this would be greatly appreciated.
Pressing one keys is just getting two events: one on press down and one on release
Pressing two keys is similar, you will get 4 events, 2 key down events and 2 key release events
If the 2 key press are close in timing and/or before the key release event, then you can assume the end user pressed them "at the same time" and drive the behavior you describe.
If you get Down Down Down Down Up ==> with same key down, it's one key with auto repeat If you get Down Down Up Up ==> two keys are pressed at same time (if key different of course) If you get Down Up Down Up ==> two keys in a row, possibly same one
The functions you want to implement in your Processing program:
[b]keyPressed()[/b] function which is called once every time a key is pressed. The key that was pressed is stored in the key variable. (Because of how operating systems handle key repeats, holding down a key may cause multiple calls to keyPressed(). The rate of repeat is set by the operating system, and may be configured differently on each computer. )
[b]keyReleased()[/b] function is called once every time a key is released. The key that was released will be stored in the key variable. See key and keyCode for more information.
(keyboard events only work when a program has draw(). Without draw(), the code is only run once and then stops listening for events).
See how keys work and associated functions