×
Namespaces

Variants
Actions

Handling keys with Symbian Web Runtime

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): Nokia N78
Compatibility
Platform(s): S60 3rd Edition, FP2
Article
Keywords: addEventListener
Created: User:Technical writer 1 (13 Jan 2009)
Last edited: hamishwillee (15 Jun 2012)

Overview

If you have disabled cursor navigation with widget.setNavigationEnabled(false); in a Web Runtime (WRT) widget you need to implement proprietary key input handling methods.

When porting a JavaScript application to WRT, the original interaction does not always work with S60 devices' input methods but you need to modify it to suite the platform. One example case would be arrow key handling.


Solution

First enable the key capturing. Call the following code when the application starts:

 document.addEventListener("keypress", this.keypressListener, false);

Also remember to remove the event listener when you quit the game by calling the following lines:

 document.removeEventListener("keypress", this.keypressListener, false);

The you just need to implement the key event listener functions and handle the key events:

 this.keypressListener = function(event) {
 
if(event.keyCode == 63495) // left
{
// call the function that handles the left arrow key
}
else if(event.keyCode == 63496) // right
{
// call the function that handles the right arrow key
}
else if(event.keyCode == 63497) // up
{
// call the function that handles the up arrow key
}
else if(event.keyCode == 63498) // down
{
// call the function that handles the down arrow key
}
else if(event.keyCode == 63557) // middle button
{
// call the function that handles the middle button
}
};


Related resources

An example application ported to S60 WRT using this method is available at File:Tetris.zip. The original code for the PC browser environment is available at Browser Tetris.

This page was last modified on 15 June 2012, at 03:55.
66 page views in the last 30 days.
×