The TV Input Device API provides functions to subscribe key events of the input device.
The following remote control keys are mandatory input device keys. They are available to an application on any Tizen TV.
The Tizen TV may provide additional keys depending on a particular input device. An application can handle device dependent key events after registration.
Since: 2.3
Name which identifies the key
typedef DOMString InputDeviceKeyName;
Name of the key may be, for example:
The actual list of supported keys depends on the platform.
The TVInputDeviceManager interface defines what is instantiated in the tizen object.
[NoInterfaceObject] interface TVInputDeviceManagerObject { readonly attribute TVInputDeviceManager tvinputdevice; };
Tizen implements TVInputDeviceManagerObject;
There is a tizen.tvinputdevice object that allows accessing the functionality of the TV Input Device API.
The InputDeviceKey interface stores information about the key.
[NoInterfaceObject] interface InputDeviceKey { readonly attribute InputDeviceKeyName name; readonly attribute long code; };
The TVInputDeviceManager interface provides the features to check for availability and register for input device events.
[NoInterfaceObject] interface TVInputDeviceManager { InputDeviceKey[] getSupportedKeys() raises(WebAPIException); InputDeviceKey? getKey(InputDeviceKeyName keyName) raises(WebAPIException); void registerKey(InputDeviceKeyName keyName) raises(WebAPIException); void unregisterKey(InputDeviceKeyName keyName) raises(WebAPIException); void registerKeyBatch(InputDeviceKeyName[] keyNames, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void unregisterKeyBatch(InputDeviceKeyName[] keyNames, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); };
getSupportedKeys
Retrieves the list of keys can be registered with the registerKey() method.
InputDeviceKey[] getSupportedKeys();
Mandatory keys will not be retrieved by this method.
Privilege level: public
Privilege: http://tizen.org/privilege/tv.inputdevice
Exceptions:
Code example:
var i, keyCode = {}, supportedKeys; supportedKeys = tizen.tvinputdevice.getSupportedKeys(); for (i = 0; i < supportedKeys.length; i++) { keyCode[supportedKeys[i].name] = supportedKeys[i].code; } if(keyCode.hasOwnProperty("ChannelUp")) { tizen.tvinputdevice.registerKey("ChannelUp"); } window.addEventListener("keydown", function(keyEvent) { // identify the key by the numeric code from the keyEvent if(keyEvent.keyCode === keyCode.ChannelUp) { console.log("The CHANNEL UP was pressed"); } });
getKey
Returns information about the key which has the given name.
InputDeviceKey? getKey(InputDeviceKeyName keyName);
Parameters:
Return value: InputDeviceKey InputDeviceKey object for the given key name, or null if the key is not supported
registerKey
Registers an input device key to receive DOM keyboard event when it is pressed or released.
void registerKey(InputDeviceKeyName keyName);
When an application wants to react to the Input Device keys being pressed, it should register this key.
An application cannot register the mandatory keys (ArrowLeft, ArrowRight, ArrowUp, ArrowDown, Enter, Back).
var keys = ["VolumeUp", "VolumeDown"], i; for (i = 0; i < keys.length; i++) { try { tizen.tvinputdevice.registerKey(keys[i]); } catch(error) { console.log("failed to register " + keys[i] + ": " + error); } }
unregisterKey
Unregisters an input device key.
void unregisterKey(InputDeviceKeyName keyName);
tizen.tvinputdevice.unregisterKey("VolumeDown");
registerKeyBatch
Registers a batch of input device keys to receive DOM keyboard events when any of them is pressed or released.
void registerKeyBatch(InputDeviceKeyName[] keyNames, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
Since: 2.4
When an application wants to react to the input device key presses, it should register those keys.
The errorCallback is launched with this error type:
function errorCB(err) { console.log( 'The following error occurred: ' + err.name); } function successCB() { console.log('Registered successfully'); } var keys = ["VolumeUp", "VolumeDown"]; tizen.tvinputdevice.registerKeyBatch(keys, successCB, errorCB);
unregisterKeyBatch
Unregisters a batch of input device keys.
void unregisterKeyBatch(InputDeviceKeyName[] keyNames, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);
function errorCB(err) { console.log( 'The following error occurred: ' + err.name); } function successCB() { console.log('Unregistered successfully'); } var keys = ["VolumeUp", "VolumeDown"]; tizen.tvinputdevice.unregisterKeyBatch(keys, successCB, errorCB);
You can check if this API is supported with tizen.systeminfo.getCapability() and decide enable/disable codes that need this API.
To guarantee the running of this application on a device with a TV input device support, define the following requirements in the config file:
For more information, see Application Filtering.
module TVInputDevice { typedef DOMString InputDeviceKeyName; [NoInterfaceObject] interface TVInputDeviceManagerObject { readonly attribute TVInputDeviceManager tvinputdevice; }; Tizen implements TVInputDeviceManagerObject; [NoInterfaceObject] interface InputDeviceKey { readonly attribute InputDeviceKeyName name; readonly attribute long code; }; [NoInterfaceObject] interface TVInputDeviceManager { InputDeviceKey[] getSupportedKeys() raises(WebAPIException); InputDeviceKey? getKey(InputDeviceKeyName keyName) raises(WebAPIException); void registerKey(InputDeviceKeyName keyName) raises(WebAPIException); void unregisterKey(InputDeviceKeyName keyName) raises(WebAPIException); void registerKeyBatch(InputDeviceKeyName[] keyNames, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void unregisterKeyBatch(InputDeviceKeyName[] keyNames, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); }; };