Namespaces
Variants
Actions
Revision as of 06:44, 16 December 2011 by hamishwillee (Talk | contribs)

How to interpret key events in WRT widgets?

Jump to: navigation, search
Article Metadata

Compatibility
Platform(s): S60 3rd Edition FP2

Article
Created: forum-mrkt (03 Oct 2007)
Last edited: hamishwillee (16 Dec 2011)

Contents

Browser engine differences

In general, different browser engines differ in key event codes visible to JavaScript level. S60 WRT widget text and input field components do not support all key events found in the other browser or widget environments.

S60 WRT specific APIs

S60 WRT API

widget.setNavigationEnabled(false);

disables navigation mode and allows your JavaScript code to collect also cursor key events.

Example

Following simple example let's you explore different key event values provided by S60 WRT:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<script type="text/javascript">
 
/*
* attach key listeners
*/
document.onkeypress = keyPress;
document.onkeyup = keyUp;
document.onkeydown = keyDown;
 
/*
* disable cursor navigation - otherwise cursor
* key events are not received by keypress callbacks
*/
widget.setNavigationEnabled(false);
 
/*
* show keyCode and charCode.
*/
function keyPress(event) {
document.getElementById('keypressField').innerHTML = event.keyCode + " / " +
event.charCode;
}
 
function keyDown(event) {
document.getElementById('keydownField').innerHTML = event.keyCode + " / " +
event.charCode;
}
 
function keyUp(event) {
document.getElementById('keyupField').innerHTML = event.keyCode + " / " +
event.charCode;
}
</script>
 
</head>
<body>
keyCode / charCode:
 
<div>
KeyPress:
<div id="keypressField"></div>
</div>
 
<div>
Keydown:
<div id="keydownField"></div>
</div>
 
<div>
Keyup:
<div id="keyupField"></div>
</div>
 
</body>
</html>

Key and Char code table

For your reference here is collected values from test application. Format is like in example, event.keyCode / event.charCode.

keykeyPresskeyDownKeyup
048/4848/4848/48
149/4949/4949/49
250/5050/5050/50
351/5151/5151/51
452/5252/5252/52
553/5353/5353/53
654/5454/5454/54
755/5555/5555/55
856/5656/5656/56
957/5757/5757/57
*/+56/4242/4256/42
#51/3535/3551/35
C8/88/88/8
green0/6358663586/635860/63586
center0/6355763557/63557[n/a]/[n/a]
left37/6349563495/63495[n/a]/[n/a]
up38/6349763497/63497[n/a]/[n/a]
right39/6349663496/63496[n/a]/[n/a]
down40/6349863498/63498[n/a]/[n/a]
118 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved