Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 28
Registered: ‎09-28-2011
My Device: 9700 Bold
My Carrier: Vodafone
Accepted Solution

Keyboard keys?

[ Edited ]

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;         
    }

Developer
Posts: 40
Registered: ‎09-08-2011
My Device: 8900
My Carrier: AIS

Re: Keyboard keys?

Example:

 

static final int intcKeyCodeE = Keypad.keycode('E', 0);

...

public boolean keyDown(int keycode, int time) {

    if (keycode == intcKeyCodeE)

Highlighted
Contributor
Posts: 28
Registered: ‎09-28-2011
My Device: 9700 Bold
My Carrier: Vodafone

Re: Keyboard keys?

Just tried it now and works perfectly!! Thanks so much I've been struggling with this for hours! Smiley Happy