Handling Remote Control Key Events
If a TV user presses any button on the remote control, a keydown event occurs. This event is passed to an element receiving focus, and if the element has a registered function in the onkeydown property, that function is executed. The function is registered using event.keyCode.
All the remote control keys must be defined by member variables of the tvKeyValue object as follows:
- Insert an element that will have focus in the index.html file:
<a href='javascript:void(0);' id='anchor' onkeydown='Main.keyDown();'></a>
- Create a function to be registered in the onkeydown property:
Main.keyDown = function(){ // Key handler var keyCode = event.keyCode; alert("Main Key code : " + keyCode); switch (keyCode) { case tvKey.KEY_LEFT: /** * Code for Left key event! */ break; case tvKey.KEY_RIGHT: break; case tvKey.KEY_UP: break; case tvKey.KEY_DOWN: break; case tvKey.KEY_ENTER: break; case tvKey.KEY_RETURN: break; } }
Remote control keys for applications
If you access an application, the Application Manager registers basic keys relevant to it. If a key event registered in an application occurs, it is loaded to the application. However, if the key is not registered in the application, the event is not loaded to the application. If an unregistered key is executed, the TV system closes the application and TV functions become available. For example, when an application which has no registered volume key is running, and the volume key on remote control is pressed, the working application is forcibly closed and volume banner appears on TV screen.
The Application Manager registers key sets as stated below in order for the application to use keys. When the <fullwidget> tag value in the config.xml file is ‘y’ and the full-screen application keyset is ‘n’, a single-wide application is registered.
Full- screen Application |
Single-wide Application |
|
---|---|---|
KEY_VOL_UP |
KEY_1 |
KEY_WHEELDOWN |
Note: Each application registers/unregisters keys additionally by using the registKey() method of the Plugin objects common module.
Key registration/unregistration should be done after the window.onshow event. The keys registered/unregistered after the window.onshow event are processed normally, but those before the window.onshow event may be ignored.
Register a function executed in window.onshow before calling this method because window.onshow event happens after calling the sendReadyEvent() method of the Widget common module. An example is shown below:
var WIDGET = new Common.API.Widget(); // For sendReadyEvent() var TVKEY = new Common.API.TVKeyValue(); // Remote controller key value object var PLUGIN = new Common.API.Plugin(); // Plugin common module Main.onLoad = function(){ window.onshow = function(){ // register the onshow event callback PLUGIN.registKey(TVKEY.KEY_VOL_UP); PLUGIN.registKey(TVKEY.KEY_VOL_DOWN); } WIDGET.sendReadyEvent(); /** * code */ }
The time of key registration/unregistration after the window.onshow event does not matter.