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
Highlighted
Contributor
Posts: 12
Registered: ‎06-04-2013
My Device: Z10
My Carrier: Vodafone
Accepted Solution

Making a BB10 WebWorks application keyboard compatible for Q10

Hi,

 

I have been asked to port a WebWorks application originally designed for the Z10 to the Q10.

 

One of the requirements is to make the application keyboard compatible.

 

What they mean by this is that within the application a user is presented with a series of options on screen; A, B, C, D.

 

On the Z10 they can just use the touch screen but they want users on a Q10 to be able to keypress A, B, C or D and have that trigger that selection option also.

 

Is this available in th WebWorks API?

Retired
Posts: 1,382
Registered: ‎07-02-2009
My Device: BlackBerry Bold 9900
My Carrier: Bell

Re: Making a BB10 WebWorks application keyboard compatible for Q10

Yes, you can do this with event listeners and the keypress or keydown events.

 

When someone presses keyboard events, these events are fired and you can then map them to appropriate JavaScript functionality.

 

Here is a sample that demonstrates key events:

http://blackberry.github.io/WebWorks-Samples/kitchenSink/html/browser/keyevents.html

 

Here's a code snippet that should help you solve your problem:

window.addEventListener("load", function(ee) {

   document.addEventListener("keydown", function(e) {
      var theChar = String.fromCharCode(e.keyCode);

      switch(theChar) {

         case "a":
            alert("a");
            break;

         case "b":
            alert("b")
            break;
         default:
            alert("unsupported char : " + theChar)
      }

   },  false);

}, false);

 

Follow me on Twitter: @n_adam_stanley
-------------------------------------------------------------------------------------------------------------------------
Your app doesn't work? Use BlackBerry remote web inspector to find out why.
Contributor
Posts: 12
Registered: ‎06-04-2013
My Device: Z10
My Carrier: Vodafone

Re: Making a BB10 WebWorks application keyboard compatible for Q10

That's great thank you.