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
Highlighted
Developer
Posts: 198
Registered: ‎04-03-2009
My Device: Not Specified

Trace the keyevents at homescreen when the application is running on background

Hi,

 

 Is there any way to get the key events if my application is running on the background.

 

 I am only able to get the events of cancel, menu and  back button events.

 

 I want to get the events of the characters entered on the keyboard.

 

 

Thanks.

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Trace the keyevents at homescreen when the application is running on background

key events are only dispatched to the application in foreground.

 

Developer
Posts: 15
Registered: ‎12-06-2008
My Device: Not Specified

Re: Trace the keyevents at homescreen when the application is running on background

hi  Saficool

 

Can u plz tell me how u got the events of cancel, menu and  back button events. Am trying to get key events from a background application, but i can see thats s not possible. Any help would be appreciated.

 

regards

Manoj.S

Developer
Posts: 198
Registered: ‎04-03-2009
My Device: Not Specified

Re: Trace the keyevents at homescreen when the application is running on background

Hello Manoj,

 

 You can get the keyevents for cancel, menu button , back by implementing the KeyListener interface.

 

 Add the keyListener to your listening class and implement the methods of keylistener interface. 

 

I have removed the keylistener from my current code. So dont rememeber exactly which method was getting invoked when a key event occurs on cancel and other 3 keys. 

 

The little i remember it was the  keyChar method of keylistener which was getiing invoked.

 

Try sop in keyChar method it will return you different keyCode for 4 keys.

 

 

 

Thanks......

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

Re: Trace the keyevents at homescreen when the application is running on background

I think we might have some confusion here.  As RexDoug said, to get key Events, you have to be in the Foreground.  The OP is saying that the application is running in the Background.  The KeyListener Interface works on listening of key strokes against UI components - if the UI Component is not displayed (which typically it won't be if the Application is the Background), then that interface will not help.

 

So let us summarize the situation.

 

If the Application is not displaying something on the Display(say a Screen, PopupScreen or Dialog), then it will not receive Key Events.

 

So is there any UI Component that is owned by the Background Application being displayed on the Device at the time the Background Application wants to receive Key Events?  If the answer to this question is no, then the Application can not receive Key Events

Developer
Posts: 198
Registered: ‎04-03-2009
My Device: Not Specified

Re: Trace the keyevents at homescreen when the application is running on background

Hi Peter I only tried it out on the Simulator. My Application was a UIApplication which was in the background.

 

I added the keylistener to it and I was getting the sop's in keyChar method for only the cancel, call, menu and back key.

 

 

May be it might not work in real device but  i was only able to catch the events for the above 4 keys in keyChar method

Developer
Posts: 342
Registered: ‎02-04-2009
My Device: BB 8320

Re: Trace the keyevents at homescreen when the application is running on background

Does your application only runs in background? Or does it has any gui components associated with it?

 

If its background application, then you want to extend Application instead of UiApplication. 

 

Reference:

 

http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&message.id=25866#M25866 


Use Search. "Accept Solution" if the problem gets resolved.
Developer
Posts: 198
Registered: ‎04-03-2009
My Device: Not Specified

Re: Trace the keyevents at homescreen when the application is running on background

Its an UIApplication with UI thats why I extended UIApplication.

 

 

Thanks...

Developer
Posts: 342
Registered: ‎02-04-2009
My Device: BB 8320

Re: Trace the keyevents at homescreen when the application is running on background

@ safycoolI added the keylistener to it and I was getting the sop's in keyChar method for only the cancel, call, menu and back key.

While your application is running as background after calling requestBackground(), does your keyChar method able to get those four keys still then?


Use Search. "Accept Solution" if the problem gets resolved.
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Trace the keyevents at homescreen when the application is running on background

@safycool - Interesting, I was not aware that it was even possible to get those 4 keys!  I will have to give it a try.  Can you tell me what level of JDE/Simulator you are using and I will try it myself.  Cheers