I am using keyboard_key variable from here:
//overrides the function keyPressed from "lcdui.Canvas"
protected void keyPressed(int keyCode){
keyboard_key = keyCode;
}
to detect if any key was pressed on a mobile phone.
But it returns only the key that is pressed most lately and it doesn’t tell if any other key might be pressed. Please help!
Btw, I’m using NetBeans 7.0.1 as IDE.
The way you use it in your code snippet,
keyboard_keywill always contain only the key that is pressed most lately – just because it “has no room” to hold anything more than that.Consider using Vector to “memorize” different keys that were pressed.
Side note given the question, you may benefit from studying Java language basics. There are many tutorials available online – just search the web for something like “Java getting started”.
Depending on your application requirements, consider overriding keyRepeated along with keyPressed.
If you intend to handle key presses in game-loop fashion (“multiple keys at once” suggest that you may possibly have this in mind), consider another option provided by
lcdui.game.GameCanvasAPI, method getKeyStates():