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: 64
Registered: ‎05-06-2009
My Device: Not Specified

Hardware buttons capture / listen

Greetings is there a way to listen to or capture the hardware buttons on my blackberry? Eg, I would like to have my program respond to the camera button or any other buttons. Thanks
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Hardware buttons capture / listen

When your app is in the foreground, then this is easy, your screen will pick this up.  When your app is in the background, a KeyListener will pick up some key presses, however my experience is that this will depend on the OS level and the type of device.  So I'm not sure that you will always be able to pick up the camera button for example.  Something to test.  But not on the Simulator - it is different again.....

 

Not sure this has helped at all.....

Developer
Posts: 64
Registered: ‎05-06-2009
My Device: Not Specified

Re: Hardware buttons capture / listen

What function do I need to use or override on screen to see the button?
Developer
Posts: 110
Registered: ‎10-22-2009
My Device: 9700
My Carrier: ChinaMobile

Re: Hardware buttons capture / listen

as what peter said, add the below code to your screen to catch what you press

 

public boolean keyChar(char key, int status, int time) 

 

Best Regards,
Tiandi
www.tiandiyoyo.com
Developer
Posts: 64
Registered: ‎05-06-2009
My Device: Not Specified

Re: Hardware buttons capture / listen

These look to me like the normal keyboard buttons. I was after the buttons such as camera, volume buttons and other buttons on the side
Developer
Posts: 110
Registered: ‎10-22-2009
My Device: 9700
My Carrier: ChinaMobile

Re: Hardware buttons capture / listen

you can also use keyDown(int keycode, int time)  or keyUp(int keycode, int time)  to detect convenience key.

Best Regards,
Tiandi
www.tiandiyoyo.com
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Hardware buttons capture / listen

Have a look at Characters, KeyPad, and KeyPadListener classes/interfaces for information on converting from the various forms and detecting the convenience keys. 

Developer
Posts: 64
Registered: ‎05-06-2009
My Device: Not Specified

Re: Hardware buttons capture / listen

Ok - so it appears to me that you actually need to set the convenience key from your settings first before being able to detect it. So by default, the right convenience key is set to camera, so when I press it I do not get a keychar event.