This topic describes how your application can receive input from a remote control.
TVInputDevice API
Keyboard Event Types
The remote control is the most common way for users to interact with the device.
Figure 1. Samsung Smart Signage Remote
To use the TVInputDevice API, the application has to request permission by adding the following privilege to the "config.xml" file:
<tizen:privilege name='http://tizen.org/privilege/tv.inputdevice'> </tizen:privilege>
To detect and handle remote control key clicks:
To retrieve information about the remote control keys that the device supports, use the getSupportedKeys() method:
getSupportedKeys()
var value = tizen.tvinputdevice.getSupportedKeys(); console.log(value);
The method returns the key name and keyCode value for each supported key.
keyCode
To register the key, add the registerKey() method to the onload event, with the key name as the parameter:
registerKey()
onload
tizen.tvinputdevice.registerKey('MediaPlayPause'); tizen.tvinputdevice.registerKey('ColorF0Red');
Since 2016 models, you can batch register keys using the registerKeyBatch() method, which can improve application launch time:
registerKeyBatch()
tizen.tvinputdevice.registerKeyBatch(['VolumeUp', 'VolumeDown']);
Note The "ArrowLeft", "ArrowUp", "ArrowRight", "ArrowDown", "Enter", and "Back" key events are detected automatically, and do not require separate registration.
The "ArrowLeft", "ArrowUp", "ArrowRight", "ArrowDown", "Enter", and "Back" key events are detected automatically, and do not require separate registration.
To receive notifications when a remote control key is clicked, add a listener for the keydown event:
keydown
<body ... onkeydown='handleKeydown(event);'> ... </body>
or
document.body.addEventListener('keydown', handleKeyDown);
For more information on the keydown event, see the W3C Keyboard Event Types.
Define the listener. The parameter of the handleKeyDown() method is the keyCode value for the clicked key.
handleKeyDown()
function handleKeydown(event) { switch (event.keyCode) { case tizen.tvinputdevice.getKey('MediaPlayPause').code: //10252 // Something you want to do break; case tizen.tvinputdevice.getKey('ColorF0Red').code: //403 // Something you want to do break; ...
The following table lists the remote control key names and their corresponding keyCode values.