Registering keys from the remote control

787

Brief tutorial on how to correctly register the remote control keys for the Tizen Based Samsung Smart TV platform

Requirements:

  1. Tizen SDK or your favorite text editor (just for the code).
  2. Name of all the keys in Tizen (this will be at the end).
  3. Privilege: http://tizen.org/privilege/tv.inputdevice.

Registering your keys will make your app support additional keys than the defaults.

The default keys that Tizen supports are:

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

In the config.xml file we add the privilege like the example below:

<tizen:privilege name="http://tizen.org/privilege/tv.inputdevice"/>

We now have everything we need to register our keys. I have placed the following snippet code below which I will also explain.

//tvKey is where the supported keys will be stored and i is the incremental variable for the loops
var tvKey ={}, i;

//supportedKeys will be assigned by the keys that the TV will support
var supportedKeys = tizen.tvinputdevice.getSupportedKeys();

//keys will be the keys that you need in your app
var keys = ["MediaPlay", "MediaPause", "MediaStop", "MediaPlayPause"];

//In this loop the supported keys will be stored on tvKey. The key is given the name and the value of the code for the supported key.
for (i = 0; i < supportedKeys.length; i++) {
 tvKey[supportedKeys[i].name] = supportedKeys[i].code;
}

//In this loop we will check if the key that we want to register has properties. If it does, we will try to register it. 
for (i = 0; i < keys.length; i++) {
 if(tvKey.hasOwnProperty(keys[i])) {
  try{
   tizen.tvinputdevice.registerKey(keys[i]);
  }
  catch(e){
   console.log(e);
  }
 }
}

Standard Control Samsung Smart TV
Registering-keys-basicControl

Smart Control for Samsung Smart TV 2015

Registering-keys-tizenControl

 

Now that we have our keys registered, we need a key listener. In the body tag, we can add the property onkeydown and call a function where all the keys are controlled.

Here is the list of the key codes. Name is the name of the key that you would use to register.

 
Name: 0, Code: 48
Name: 1, Code: 49
Name: 2, Code: 50
Name: 3, Code: 51
Name: 3D, Code: 10199
Name: 4, Code: 52
Name: 5, Code: 53
Name: 6, Code: 54
Name: 7, Code: 55
Name: 8, Code: 56
Name: 9, Code: 57
Name: Caption, Code: 10221
Name: ChannelDown, Code: 428
Name: ChannelList, Code: 10073
Name: ChannelUp, Code: 427
Name: ColorF0Red, Code: 403
Name: ColorF1Green, Code: 404
Name: ColorF2Yellow, Code: 405
Name: ColorF3Blue, Code: 406
Name: E-Manual, Code: 10146
Name: Exit, Code: 10182
Name: Extra, Code: 10253
Name: Guide, Code: 458
Name: Info, Code: 457
Name: MTS, Code: 10195
Name: MediaFastForward, Code: 417
Name: MediaPause, Code: 19
Name: MediaPlay, Code: 415
Name: MediaPlayPause, Code: 10252
Name: MediaRecord, Code: 416
Name: MediaRewind, Code: 412
Name: MediaStop, Code: 413
Name: MediaTrackNext, Code: 10233
Name: MediaTrackPrevious, Code: 10232
Name: Menu, Code: 457
Name: Minus, Code: 189
Name: PictureSize, Code: 10140
Name: PreviousChannel, Code: 10190
Name: Search, Code: 10225
Name: Soccer, Code: 10228
Name: Source, Code: 10072
Name: Teletext, Code: 10200
Name: Tools, Code: 10135
Name: VolumeDown, Code: 448
Name: VolumeMute, Code: 449
Name: VolumeUp, Code: 447

That is all there is to it. Thank you!

NO COMMENTS

LEAVE A REPLY

20 − 19 =