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:

  1. Insert an element that will have focus in the index.html file:
    <a href='javascript:void(0);' id='anchor' onkeydown='Main.keyDown();'></a> 
  2. 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_VOL_DOWN
KEY_MUTE
KEY_TOOLS
KEY_INFO
KEY_EMODE
KEY_DMA
KEY_MENU
KEY_SOURCE
KEY_PRECH
KEY_FAVCH
KEY_CHLIST
KEY_DMA
KEY_TTX_MIX
KEY_GUIDE
KEY_SUBTITLE
KEY_ASPECT
KEY_DOLBY_SRR
KEY_MTS
KEY_PANEL_CH_UP
KEY_PANEL_CH_DOWN
KEY_PANEL_VOL_UP
KEY_PANEL_VOL_DOWN
KEY_PANEL_ENTER
KEY_PANEL_SOURCE
KEY_PANEL_MENU

KEY_1
KEY_2
KEY_3
KEY_4
KEY_5
KEY_6
KEY_7
KEY_8
KEY_9
KEY_0
KEY_WHEELDOWN
KEY_WHEELUP
KEY_RED
KEY_GREEN
KEY_YELLOW
KEY_BLUE
KEY_RW
KEY_PAUSE
KEY_FF
KEY_PLAY
KEY_STOP
KEY_ENTER
KEY_RETURN
KEY_EXIT

KEY_WHEELDOWN
KEY_WHEELUP
KEY_RED
KEY_GREEN
KEY_YELLOW
KEY_BLUE
KEY_RW
KEY_PAUSE
KEY_FF
KEY_PLAY
KEY_STOP
KEY_ENTER
KEY_RETURN
KEY_EXIT

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.

Where to Go Next