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
New Contributor
banders
Posts: 6
Registered: ‎05-12-2012
My Device: Bold 9900

Webworks App doesn't respond to key events until screen touch

Hello,

 

I'm building a webworks game that listens for keypress events (alphabetic keys) to control actions.  There are no form elements on the page... all of the content is rendered within <div> tags.  On a Blackberry Bold 9900, the keypress event doesn't when the app first loads.  After I touch the screen once, then events will fire until I exit the app.

 

I can't figure out how to make the app respond to keypress events from the get go (without requiring the I first touch the screen).  I've variously tried forcing focus on the document on the window, on the target div, but none of that seems to work. 

 

Any suggestions?

 

Cheers

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

Re: Webworks App doesn't respond to key events until screen touch

I can't seem to reproduce this on my 9900. 

 

Using the following test page, loaded within a WebWorks app (or the browser), I am seeing keyPress events even before I touch the screen:

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

 

 

Can you provide a code sample that reproduces the behavior you are seeing?

 

Have you used web inspector to identify whether there are errors or messages happening that help to explain the behavior you are seeing?

Follow me on Twitter: @n_adam_stanley
-------------------------------------------------------------------------------------------------------------------------
Your app doesn't work? Use BlackBerry remote web inspector to find out why.
New Contributor
banders
Posts: 6
Registered: ‎05-12-2012
My Device: Bold 9900

Re: Webworks App doesn't respond to key events until screen touch

Here's a simple example can can be used to reproduce the problem.  I think what's key here is that there are no form elements on the page.  I've noticed that keypress events are immediately responsive (i.e. the problem I describe doesn't occur) if the default focus lands on a textfield.  However, my app won't have form elements... it's just a game with everything displayed in <div> tags.

 

<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,height=device-height,user-scalable=no,initial-scale=1.0">

 

<script type="text/JavaScript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/JavaScript">

   $(document).keypress(function() {
       alert("Handler for .keypress() called.");
   });

</script>
</head>
<body>

<!-- there are no form elements on this page, so keypress events don't fire until
  after the screen is touched (on a Bold 9900) -->

</body>
</html>

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

Re: Webworks App doesn't respond to key events until screen touch

Okay I understand, you are using jQuery.  I just compiled the source you posted into a WW app and deployed to my 9900.  I am able to see the alert statement when I do a keypress event - however it is delayed.  Appears to happen 1+ second after I press the key.  Not sure if you were seeing that too?

 

 

Note - I had to download a copy of jQuery-1.7.2.min.js and configure a /js folder.  Without that file in place, I was not receiving any response.  

Follow me on Twitter: @n_adam_stanley
-------------------------------------------------------------------------------------------------------------------------
Your app doesn't work? Use BlackBerry remote web inspector to find out why.
New Contributor
banders
Posts: 6
Registered: ‎05-12-2012
My Device: Bold 9900

Re: Webworks App doesn't respond to key events until screen touch

I've tried registering the event handler in differeny ways... with prototype and also without any external library.  Regardless of how I attach the handler, the keypress event only gets caught after the first screen touch.  So when my app launches, and I immediately start pressing keys on my device, no events get caught. 

 

I also notice the event delay with jquery, but that's not the issue I was concerned with.  My issue is that I'm unable to catch any keypress events (delayed or not) until after my finger touches the screen for the first time.

 

I thought it was possibly a problem with focus.  I've experimented with making explicit statements like :

 

document.focus();

window.focus();

 

I've also experimented with adding:

 

x-blackberry-focusable="true"

x-blackberry-initialFocus="true"

 

to page elements (<div> tags, etc.) in hopes that if something has focus it will allow me to catch keypress events from the get go.

 

astanley: It sounds to me like you don't experience the same problem.  Maybe I've got a different version of the headless web browser on my device??

 

Developer
asiayeah
Posts: 123
Registered: ‎11-05-2011
My Device: Z10, Bold 9900

Re: Webworks App doesn't respond to key events until screen touch


banders wrote:

I've tried registering the event handler in differeny ways... with prototype and also without any external library.  Regardless of how I attach the handler, the keypress event only gets caught after the first screen touch.  So when my app launches, and I immediately start pressing keys on my device, no events get caught. 

 

I also notice the event delay with jquery, but that's not the issue I was concerned with.  My issue is that I'm unable to catch any keypress events (delayed or not) until after my finger touches the screen for the first time.

 

I thought it was possibly a problem with focus.  I've experimented with making explicit statements like :

 

document.focus();

window.focus();

 

I've also experimented with adding:

 

x-blackberry-focusable="true"

x-blackberry-initialFocus="true"

 

to page elements (<div> tags, etc.) in hopes that if something has focus it will allow me to catch keypress events from the get go.

 

astanley: It sounds to me like you don't experience the same problem.  Maybe I've got a different version of the headless web browser on my device??

 


@banders, have we figured out this one yet?

 

I actually run into your described problem precisely. However, I am testing on BB10, 10.1.0.1485, Dev Alpha C. So I am not sure if it's a WebWorks or WebKit issues. I am NOT using jQuery, but Javascript only:

 

document.onkeypress = function (event) {

  alert("Hello");

}

 

The onkeypress isn't triggered until the screen is first touched and I only have a canvas in the html form.

New Contributor
banders
Posts: 6
Registered: ‎05-12-2012
My Device: Bold 9900

Re: Webworks App doesn't respond to key events until screen touch

No I don't resolve that problem. After many hours of experimenting with different ways to work around the problem I gave up and changed my UI so it didn't support key events.  Too bad, as the keyboard is an important part of the blackberry experience!

 

 

Developer
asiayeah
Posts: 123
Registered: ‎11-05-2011
My Device: Z10, Bold 9900

Re: Webworks App doesn't respond to key events until screen touch


banders wrote:

No I don't resolve that problem. After many hours of experimenting with different ways to work around the problem I gave up and changed my UI so it didn't support key events.  Too bad, as the keyboard is an important part of the blackberry experience!

 

 


I cannot solve it either. I left my key event support there, but as a hidden feature...it works on most cases after a single touch, but it doesn't always work...

 

Is BlackBerry WebWorks team aware of this bug?

 

Thanks.

Developer
peardox
Posts: 1,229
Registered: ‎03-20-2011
My Device: Playbook, Z10 LE, Dev Alpha B, 2x Dev Alpha C

Re: Webworks App doesn't respond to key events until screen touch

Dumb thought

 

Have you got any <input .... /> on the page? Or anything similar.?

 

Form elements, not a form...

 

Something is taking focus,

 

What you need to do is apply a blur to [whatever] and that will be the same as touching the screen (which also does a blur)

 

 




Click the like button if you find my posts useful!
Developer
asiayeah
Posts: 123
Registered: ‎11-05-2011
My Device: Z10, Bold 9900

Re: Webworks App doesn't respond to key events until screen touch

My form has no input but a canvas only.

I tried using input on a form, but without any success either. I am unable to set the initial focus on the input. That looks like another bug on its own. A touch is always required...