|
How do I use Up & Down key in my applications on my 6310i? I have searched the forum and the only useful information I have found is that those keys corresponds to KEY_UP_ARROW and KEY_DOWN_ARROW, but I still don't know how to use these constants. Can someone please help me with this?
Somewhere someone talked about a KeyListener but I can't find this in my API's! Maybe that KeyListener wasn't for 6310i... A small code example would be perfect! /Bjarne Johannessen |
|
Canvas defines the methods keyPressed and keyReleased methods. These are called when the corresponding event occurs.
Canvas also defines the method 'getGameAction(int keyCode)' and constants Canvas.DOWN,Canvas.UP,Canvas.LEFT etc etc extend Canvas, and override the keyPressed method with something like this... public void keyPressed(int keyCode) { int gameAction = getGameAction(keyCode); //btw there is a bug with getGameAction(int), //if you pass in -6 or -7 (the keyCodes for the //left and right soft keys, the emulator crashes!) switch(gameAction) { case UP: System.out.println("UP Pressed"); break; case DOWN: System.out.println("DOWN Pressed"); break; case LEFT: System.out.println("LEFT Pressed"); break; case RIGHT: System.out.println("RIGHT Pressed"); break; default: System.out.println("Some other key pressed"); } } |
|
Perfect!
That did work on my first CTRL+C & CTRL-V attempt. Thank you =) /Bjarne |
| Closed Thread | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|