Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Handling keys with Symbian Web Runtime

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


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.


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 The original code for the PC browser environment is available at Browser Tetris.

This page was last modified on 15 June 2012, at 00:55.
44 page views in the last 30 days.