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
New Developer
jk
Posts: 9
Registered: ‎07-22-2008
My Device: Not Specified

Inject KeyCodeEvent

Hello

Im using JDE 4.2.1 and 8700 emulator / device

 

For my application i need to inject some events emulating keypad input. My questions are whet are correct way of invoking action for green / red buttons. I just want to invoke exactly the same actions as if it were originated from keypad.

 Also i can't fidn correct KeyCodeEvent to emulate "cancel" / "back" button (The one below trackwheel) on 8700 series.

Any help will be very apprciated. Thnx in advance.
Please use plain text.
Administrator
MSohm
Posts: 14,528
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Inject KeyCodeEvent

These constants are in the Keypad class.  Keypad.KEY_END is the red key, Keypad.KEY_SEND is the green key and Keypad.ESCAPE is the escale (back button).
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
New Developer
BlakberryNewbie
Posts: 35
Registered: ‎09-11-2008
My Device: Not Specified

Re: Inject KeyCodeEvent

Mark,

What about the menu key? Is that Keypad.KEY_MENU? I've tried to inject that and it fails every time. It fails to inject a keystroke to the menu key. It just sits there. I've used both of the following:

 

EventInjector.KeyCodeEvent menuPress   = new EventInjector.KeyCodeEvent(EventInjector.KeyCodeEvent.KEY_DOWN, Keypad.map((char)Keypad.KEY_MENU), KeypadListener.STATUS_NOT_FROM_KEYPAD, 0); 


EventInjector.KeyCodeEvent menuRelease = new EventInjector.KeyCodeEvent(EventInjector.KeyCodeEvent.KEY_UP, Keypad.map((char)Keypad.KEY_MENU), KeypadListener.STATUS_NOT_FROM_KEYPAD, 0);        

 

 

AND

 

 

EventInjector.KeyCodeEvent menuPress = new EventInjector.KeyCodeEvent(EventInjector.KeyCodeEvent.KEY_DOWN, Characters.CONTROL_MENU, KeypadListener.STATUS_NOT_FROM_KEYPAD,0); 


EventInjector.KeyCodeEvent menuRelease = new EventInjector.KeyCodeEvent(EventInjector.KeyCodeEvent.KEY_UP, Characters.CONTROL_MENU, KeypadListener.STATUS_NOT_FROM_KEYPAD,0);        

 

 

along with

 

menuPress.post();
menuRelease.post();

 

 

 

 

Please use plain text.
Administrator
MSohm
Posts: 14,528
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Inject KeyCodeEvent

Where are you trying to inject the event to?  Certain screens restrict event injection, such as the incoming call screen and various security prompts that appear to request the user grant the application access to do something.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
New Developer
BlakberryNewbie
Posts: 35
Registered: ‎09-11-2008
My Device: Not Specified

Re: Inject KeyCodeEvent

Mark,

I am on the "call log" screen when trying to inject the menu button key.

 

Please use plain text.
Administrator
MSohm
Posts: 14,528
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Inject KeyCodeEvent

The BlackBerry 8700 does not have a menu key.  The BlackBerry Pearl 8100 was the first BlackBerry handheld to have one.  Are you seeing this on BlackBerry models that do have a menu key?

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
New Developer
BlakberryNewbie
Posts: 35
Registered: ‎09-11-2008
My Device: Not Specified

Re: Inject KeyCodeEvent

Mark,

This is a BlackBerry Curve 8310. It does have a menu key.

Please use plain text.
Administrator
MSohm
Posts: 14,528
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Inject KeyCodeEvent

I tried your first set of event injector statements and they did work on a a BlackBerry 8310.  What happens when you try?  Is any exception thrown?  Has the application been given permissions for Input Simulation?  You can change this by going to Options, Advanced Options, Applications, select the application and choose Edit Permissions from the menu.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
New Developer
BlakberryNewbie
Posts: 35
Registered: ‎09-11-2008
My Device: Not Specified

Re: Inject KeyCodeEvent

Mark,

    When I execute the following code:

 

"Invoke.invokeApplication( Invoke.APP_TYPE_PHONE, new PhoneArguments() );

 

EventInjector.KeyCodeEvent menuPress   = new EventInjector.KeyCodeEvent(EventInjector.KeyCodeEvent.KEY_DOWN,  Keypad.map((char)Keypad.KEY_MENU), KeypadListener.STATUS_NOT_FROM_KEYPAD, 0); 


EventInjector.KeyCodeEvent menuRelease = new EventInjector.KeyCodeEvent(EventInjector.KeyCodeEvent.KEY_UP, Keypad.map((char)Keypad.KEY_MENU), KeypadListener.STATUS_NOT_FROM_KEYPAD, 0);      

 

menuPress.post();
menuRelease.post();"

 

 

NO exception is ever thrown. I have also confirmed through Options--> Advanced Options-->Applications that my app has keystroke injection permissions allowed. The only other thing I can tell you, is that when I run this application while attached to the JDE debugger, this is what I get in the console window when it attempts to  execute the post() lines:

 

"Foreground net_rim_bb_phone_app(75)
UIE: Focus - target lost, prev=net.rim.device.apps.internal.phone.PhoneAppScreen@82b394d9
UIE: Focus - target lost, prev=net.rim.device.apps.internal.phone.PhoneAppScreen@82b394d9

"

Please use plain text.
New Developer
BlakberryNewbie
Posts: 35
Registered: ‎09-11-2008
My Device: Not Specified

Re: Inject KeyCodeEvent

Mark,

Additionally, when I run the application, the only thing it does is to invoke the built-in phone application. It does not bring up the menu inside of that app as I have injected it to do.

Please use plain text.