07-18-2012 05:15 PM - edited 07-18-2012 05:17 PM
Hello,
In my app I need to capture the keyDown() and keyUp() events when a normal character key on the keyboard is pressed. For example the app should be able to execute a method when the R key is pressed then different method when it is released. Because it needs execute different methods when pressed and released, keyChar() won't work. The problem is, I don't seem to be able to get the key codes for the normal keyboard keys. I can for the special keys like the delete and space bar keys but can't for the normal character keys. How do I get the key codes for characters for using in keyDown() and keyUp()? Keypad.getKeyCode(char, 0) doesn't seem to return the right code?
Heres my code as it stands:
public boolean keyDown(int keyCode, int time) {
int s = Keypad.getKeyCode(Characters.LATIN_SMALL_LETTER_S, 0);
int r = Keypad.getKeyCode(Characters.LATIN_SMALL_LETTER_R, 0);
if (keyCode == s){
bool1=true;
}
if (keyCode == r){
method1();
}
return false;
}
public boolean keyUp(int keyCode, int time) {
int s = Keypad.getKeyCode(Characters.LATIN_SMALL_LETTER_S, 0);
int r = Keypad.getKeyCode(Characters.LATIN_SMALL_LETTER_R, 0);
if (keyCode == s){
bool1 = false;
}
if (keyCode == r){
method2();
}
return false;
}
Solved! Go to Solution.
07-18-2012 07:52 PM
Example:
static final int intcKeyCodeE = Keypad.keycode('E', 0);
...
public boolean keyDown(int keycode, int time) {
if (keycode == intcKeyCodeE)
07-18-2012 08:09 PM