Handling keys with Symbian Web Runtime
Article Metadata
Tested with
Compatibility
Article
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.

