TVInputDevice API

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.

  • ArrowLeft, ArrowUp, ArrowRight, ArrowDown
  • Enter
  • Back

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

Summary of Interfaces and Methods

Interface Method
TVInputDeviceManagerObject

InputDeviceKey

TVInputDeviceManager

InputDeviceKey[] getSupportedKeys ()

InputDeviceKey? getKey (InputDeviceKeyName keyName)

void registerKey (InputDeviceKeyName keyName)

void unregisterKey (InputDeviceKeyName keyName)

void registerKeyBatch (InputDeviceKeyName[] keyNames, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)

void unregisterKeyBatch (InputDeviceKeyName[] keyNames, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)

1. Type Definitions

1.1. InputDeviceKeyName

Name which identifies the key

typedef DOMString InputDeviceKeyName;

Name of the key may be, for example:

  • VolumeUp
  • VolumeDown
  • ChannelUp
  • ChannelDown

The actual list of supported keys depends on the platform.

2. Interfaces

2.1. TVInputDeviceManagerObject

The TVInputDeviceManager interface defines what is instantiated in the tizen object.

[NoInterfaceObject] interface TVInputDeviceManagerObject {
    readonly attribute TVInputDeviceManager tvinputdevice;
};
Tizen implements TVInputDeviceManagerObject;

Since: 2.3

There is a tizen.tvinputdevice object that allows accessing the functionality of the TV Input Device API.

2.2. InputDeviceKey

The InputDeviceKey interface stores information about the key.

[NoInterfaceObject] interface InputDeviceKey {
    readonly attribute InputDeviceKeyName name;

    readonly attribute long code;
};

Since: 2.3

Attributes

  • readonly InputDeviceKeyName name

    The name of the key, for example "VolumeUp" or "ChannelDown".

    If the key is listed in the DOM Level 3 KeyboardEvent key Values specification, the name attribute is equal to the key value specified there. (The Media Controller Keys section is the most relevant to the Input Device API) If the "DOM Level 3 KeyboardEvent key Value" does not contain appropriate entry for the key, then the Input Device provides a device specific name.

    Since: 2.3

  • readonly long code

    The numeric code of the key, like 37 or 13.

    This is the keyCode attribute value of the Key Event generated by the key.

    Since: 2.3

2.3. TVInputDeviceManager

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);
};

Since: 2.3

Methods

getSupportedKeys

Retrieves the list of keys can be registered with the registerKey() method.

InputDeviceKey[] getSupportedKeys();

Since: 2.3

Mandatory keys will not be retrieved by this method.

Privilege level: public

Privilege: http://tizen.org/privilege/tv.inputdevice

Exceptions:

  • WebAPIException
    • with error type SecurityError, if the application does not have the privilege to call this method.
    • with error type UnknownError in case of any error.

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);

Since: 2.3

Privilege level: public

Privilege: http://tizen.org/privilege/tv.inputdevice

Parameters:

  • keyName: The name of the key to retrieve

Return value:

InputDeviceKey InputDeviceKey object for the given key name, or null if the key is not supported

Exceptions:

  • WebAPIException
    • with error type SecurityError, if the application does not have the privilege to call this method.
    • with error type InvalidValuesError if the given keyName is invalid (e.g. name is empty string)
    • with error type UnknownError in any other error case.

registerKey

Registers an input device key to receive DOM keyboard event when it is pressed or released.

void registerKey(InputDeviceKeyName keyName);

Since: 2.3

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).

Privilege level: public

Privilege: http://tizen.org/privilege/tv.inputdevice

Parameters:

  • keyName: The name of the key which should generate DOM key events when pressed

Exceptions:

  • WebAPIException
    • with error type SecurityError, if the application does not have the privilege to call this method.
    • with error type InvalidValuesError, if the given keyName is invalid or not supported (e.g. name is empty string).
    • with error type UnknownError in any other error case.

Code example:

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);

Since: 2.3

Privilege level: public

Privilege: http://tizen.org/privilege/tv.inputdevice

Parameters:

  • keyName: The name of the key which should not be monitored any longer

Exceptions:

  • WebAPIException
    • with error type SecurityError, if the application does not have the privilege to call this method.
    • with error type InvalidValuesError, if the given keyName is invalid or not supported (e.g. name is empty string).
    • with error type UnknownError in any error case.

Code example:

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.

An application cannot register the mandatory keys (ArrowLeft, ArrowRight, ArrowUp, ArrowDown, Enter, Back).

The errorCallback is launched with this error type:

  • InvalidValuesError: If any of the given keyNames is invalid or not supported.
  • UnknownError: In case of any other error.

Privilege level: public

Privilege: http://tizen.org/privilege/tv.inputdevice

Parameters:

  • keyNames: The array with the names of the keys which will generate DOM key events when they are pressed
  • successCallback [optional] [nullable]: Callback method to be invoked when keys are registered
  • errorCallback [optional] [nullable]: Callback method to be invoked when an error has occurred

Exceptions:

  • WebAPIException
    • with error type SecurityError, if the application does not have the privilege to call this method.
    • with error type InvalidValuesError, if any of the given keyNames is invalid or not supported (e.g. name is empty string).
    • with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.
    • with error type UnknownError in any other error case.

Code example:

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);

Since: 2.4

The errorCallback is launched with this error type:

  • InvalidValuesError: If any of the given keyNames is invalid or not supported.
  • UnknownError: In case of any other error.

Privilege level: public

Privilege: http://tizen.org/privilege/tv.inputdevice

Parameters:

  • keyNames: The array with the names of the keys to unregister
  • successCallback [optional] [nullable]: Callback method to be invoked when keys are unregistered
  • errorCallback [optional] [nullable]: Callback method to be invoked when an error has occurred

Exceptions:

  • WebAPIException
    • with error type SecurityError, if the application does not have the privilege to call this method.
    • with error type InvalidValuesError, if any of the given keyNames is invalid or not supported (e.g. name is empty string).
    • with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.
    • with error type UnknownError in any error case.

Code example:

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:

  • http://tizen.org/feature/tv.inputdevice

For more information, see Application Filtering.

4. Full WebIDL

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);
  };

};