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

Web and WebWorks Development

Reply
Contributor
deedubbu
Posts: 35
Registered: ‎07-07-2011
My Device: Torch
Accepted Solution

onHardwareKey for convenience buttons not working

I'm trying to capture the use of the start call, menu, back, end call, volume up/down and convenience buttons in order to override their behavior. I am using the blackberry.system.event.onHardwareKey API.  It works fine for all the keys except for blackberry.system.event.KEY_CONVENIENCE_1 and blackberry.system.event.KEY_CONVENIENCE_2.  These two keys do not seem to be captured in the simulator (OS 5 and 6) or device (OS 6 Torch 9800).  Are the convenience keys able to be captured?

 

Here is the simple code I'm using

 

function cvnEvent(e) {
    alert("Caught convenience button 1");
}
 
blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_CONVENIENCE_1, cvnEvent);
Contributor
deedubbu
Posts: 35
Registered: ‎07-07-2011
My Device: Torch

Re: onHardwareKey for convenience buttons not working

Has anyone been able to successfully capture the convenience buttons through blackberry.system.event.onHardwareKey?

Retired
jeffheifetz
Posts: 518
Registered: ‎07-18-2011
My Device: Bold

Re: onHardwareKey for convenience buttons not working

Hi deedubbu,

 

This is caused by a small bug in the framework.The webworks framework will delay sending key events so the system can handle them first (this allows things like letting the back key close menus instead of leaving you with them stuck opened). Unfortunately, the convenience key when set to launch an app will launch before hitting the delayed event.

 

The fastest way to fix this is to modify the templates yourself, as the soonest it will be fixed will be in the Golf release. 

Go to the packager directory and open the file device_templates\blackberry\web\widget\listener\HardwareKeyListener.java . Go to Line 78 in the keyDown method and modify it to match the code below.

 

    /**
     * @see KeyListener#keyDown(int, int)
     */
    public boolean keyDown( int keycode, int time ) {
        _storedEvent = new StoredEvent( KEY_DOWN, keycode, time );
        int key = Keypad.key( keycode );
        if( key == Keypad.KEY_SEND || key == Keypad.KEY_END || key == Keypad.KEY_CONVENIENCE_1 || key == Keypad.KEY_CONVENIENCE_2) {
            // fire the event right away because these two keys do not trigger
            // WidgetScreen.keyCharUnhandled callback.
            return fireStoredEvent();
        }
        return false;
    }

 



1.Please resolve your thread by clicking the "Accept as Solution" button below the post which solved your problem!
2. If any post helps you please click the button below the post(s)
Contributor
deedubbu
Posts: 35
Registered: ‎07-07-2011
My Device: Torch

Re: onHardwareKey for convenience buttons not working

Thank you.  Wanted to make sure it was a bug and not something I was doing.  I look forward to seeing the fix in the next release.

Contributor
deedubbu
Posts: 35
Registered: ‎07-07-2011
My Device: Torch

Re: onHardwareKey for convenience buttons not working

Should I open an issue on github to track this?  Looking at latest source I'm not seeing the fix yet.

Retired
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: onHardwareKey for convenience buttons not working

The latest source code isn't uploaded to the repository yet...

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Regular Contributor
genvej
Posts: 58
Registered: ‎01-19-2011
My Device: 9800

Re: onHardwareKey for convenience buttons not working

Contributor
deedubbu
Posts: 35
Registered: ‎07-07-2011
My Device: Torch

Re: onHardwareKey for convenience buttons not working

I have confirmed that this issue is resolved in WebWorks SDK v2.3.  I believe this particular issue was fixed in WebWorks SDK v2.2 but my testing was limited by http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/onHardwareKey-broken-in-WebWorks... which is now resolved.