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

New Developer
Posts: 19
Registered: ‎07-22-2008
My Device: Not Specified

Problem getting a character from a keycode



I'm developing a J2ME applicaction for usual cell phones and for BlackBerry. The BlackBerry version of the aplicaciton is almost all in J2ME except for some references to the BlackBerry API.


My problem is that I'm getting the keycode of the key pressed by the user with the function:

Canvas.keyPressed(int keyCode)


and when I use that keyCode to get the character of the key pressed with the function:

char charBB = net.rim.device.api.ui.Keypad.map(keyCode);


it does't work and I always get the character '\u0000'


I've also tested with this code but neither work:

int keyBB = net.rim.device.api.ui.Keypad.key(keyCode);
int statusBB = net.rim.device.api.ui.Keypad.status(keyCode);
char charBB = net.rim.device.api.ui.Keypad.map(keyBB, statusBB);


And also this code neither work:

char charBB = net.rim.device.api.ui.KeypadUtil.getKeyChar(keyCode, net.rim.device.api.ui.KeypadUtil.MODE_EN_LOCALE);



I've debuged the code, and for example pressing the key "J" on the BlackBerry keyboard i get:

keyCode = 106

keyBB = 0

statusBB = 106

charBB = '\u0000'


charBB should be 'j' instead of '\u0000'


Why it doesn't work?



The problem could be the way of getting the keyCode, I use Canvas.keyPressed(int keyCode)  and perhaps it should be done with the BlackBerry KeyListener. But I use the Canves.keyPressed(int keyCode) because this application also runs in usual J2ME cell phones.

Is there any way to get the character pressed on the BlackBerry keyboard and continue ussing Canvas.keyPressed(int keyCode)?




Posts: 94
Registered: ‎10-01-2009
My Device: Not Specified

Re: Problem getting a character from a keycode

Have you looked at this MIDlet Guide? It has a section on keyboard input.

Posts: 484
Registered: ‎07-17-2008
My Device: Not Specified

Re: Problem getting a character from a keycode

char ch = (char)keyCode;
Posts: 4,539
Registered: ‎06-26-2013
My Device: Curve 8520

Re: Problem getting a character from a keycode

This topic has now been locked as it has been dormant for some time.


If you want to discuss this further or you have a similar question/issue please create a new post.


Steve_T                                                                                                                          New to the Community click here  
Community Moderator
Likes2.png  AS3.png  CG2.png