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
New Developer
sagar_e
Posts: 21
Registered: ‎09-23-2008
My Device: Not Specified

how do i capture blackberry specific keys ?

Hi All, I am very new to blackberry development. I have my application which is developed using normal j2me.I just want to port that application for blackberry.But the problem is i also want to capture some blackberry specific keys like say the pressing of escape key or so.I explored the blackberry api a bit and came to know about the keyListener interface but i tried to implement that interface in my subclass which extends canvas and i am unable to get proper character in the keyChar method? I guess may be I am mixing j2me and blackberry?Can anyone please help me out about how should i proceed.Thanks in advance.

Thanks

Sagar

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: how do i capture blackberry specific keys ?

I don't know whether you can mix these two up at this level, but if your KeyListener methods are being driven, then I guess to works!

 

Here is a very simple keyChar method that might help you.

 

public boolean keyChar(char key, int status, int time) { //intercept the ESC key - exit the app on its receipt boolean retval = false; if ( key == Characters.ESCAPE) { close(); return true; } return super.keyChar(key, status, time); }

 

New Developer
sagar_e
Posts: 21
Registered: ‎09-23-2008
My Device: Not Specified

Re: how do i capture blackberry specific keys ?

Hi,

Thanks for the reply but my problem is i have made my class which extends canvas implement the keyListener interface and when i press any key the code does go in method keydown and keyUp but it goes multiple times i.e. say on pressing a single key it goes twice in keydown as well as keyUp method more over what i found was my code never goes in the keyChar method at all.Can anyone Please guide me in the rite direction.Thanks in advace

 

Thanks

Sagar

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: how do i capture blackberry specific keys ?

As noted, I'm not sure this is a supported environment so this might not work anyway.

 

Reviewing the API documentation, you will see that keyDown provides a keycode and a time.  You can turn the keycode into a char using the KeyPad.map() method.  From there you can do the test as supplied previously to detect the ESC key.

 

Hope this helps.