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
Developer
Posts: 72
Registered: ‎03-14-2009
My Device: Not Specified

Re: BlackBerry softkeys.

Hi,

I solved the problem by adding the imports


    import net.rim.device.api.system.*;
    import net.rim.device.api.ui.Keypad;


and implementing the KeyListener interface in my Canvas.


Then add it to the global Application - I do it in the CTor of my Canvas with


    Application.getApplication().addKeyListener( this );


Remember to remove it when you shutdown your app, IIRC it caused some kind
of crash if not done.


    Application.getApplication().removeKeyListener( this );


I implemented the various key* eventhandlers with the following code:


    public boolean keyChar( char key, int status, int time )
    {
        return false;
    }

    public boolean keyDown( int keyCode, int time )
    {
        int key = Keypad.key( keyCode );
        if( key >= 17 && key <= 21 ) return false;

        keyPressed( key );
        return true;
    }

    public boolean keyUp( int keyCode, int time )
    {
        int key = Keypad.key( keyCode );
        if( key >= 17 && key <= 21 ) return false;

        keyReleased( key );
        return true;
    }

    public boolean keyRepeat( int keyCode, int time )
    {
        return false;
    }

    public boolean keyStatus( int keyCode, int time )
    {
        return false;
    }


At the moment I don't remember why I skipped the keys from 17 to 21 but I'm sure I had a reason back when I wrote the code :-))


Now you get the keycodes Keypad.KEY_ESCAPE and Keypad.KEY_MENU which you may want to map to R/L softkeys.


Hope that helps.


Michael

Highlighted
Developer
Posts: 1,178
Registered: ‎02-19-2009
My Device: Not Specified

Re: BlackBerry softkeys.

Nelvin, simply the best Smiley Wink
Trusted Contributor
Posts: 104
Registered: ‎02-05-2012
My Device: Bold 9900 (primary) Z10 LE (secondary)
My Carrier: Singtel

Re: BlackBerry softkeys.

[ Edited ]

@Nelvin,

Thanks for your code. It helps me a lot.

PS. according to keycode captured during the debug, 17 is accept call button, 4098 is menu buton, 27 is back button, and 18 is end call button. So you seems not to intercept the start and end call buttons in your code.

 

regards,

pigling