Remote Control

This sample app shows the keycode received from external input devices such as magic remote control, conventional remote control, external keyboard, and so on.

webOS TV is compatible with almost all of the keycode of standard keyboards. In addition, webOS TV has its own special keycodes used only for webOS TV. These special keycodes are entered via the remote control of webOS TV. You can get these keycodes by the parameter of key event.

You can figure out whole key codes of the remote control with using this sample. However, we recommend using the key codes that mentioned in Remote Control.

Adding Event Listener

The keydown event is fired when the user presses a key on the keyboard. To handle keydown event, you need to add event listener to the document element.

document.addEventListener("keydown", function(inEvent){
  // Handling keydown Event

Handling Key Event

To handle the received keycode from keydown event, add below code in your application.

var keycode;

if(window.event) { 
    keycode = inEvent.keyCode;
} else if(e.which) { 
    keycode = inEvent.which;
switch(keycode) {
    case 38: doUp(); break;
    case 40: doDown(); break; 
    . . .


At this sample, message variable has an html tag including keycode received from keydown event. You can see the keycode in a browser.

document.addEventListener("keydown", function(inEvent){
    var message = "<h1>" + "Keycode is <lg_red>" + inEvent.keyCode + "</lg_red></h1>"+ "</br>";
    document.getElementById("results").innerHTML = message;
The keydown and keyup events delivered when SHIFT + NUM (0-9) are pressed on an HID (such as keyboard) may return incorrect codes. Here are some examples:
  • SHIFT + 9: 41
  • SHIFT + 0: 40
Note that the keypress events for the above inputs return correct codes. (e.g. SHIFT + 9: 40, SHIFT + 0: 41)
Undefined input might be delivered as keycode 0. Make sure to not use keycode 0 for event handling.


For your understanding on the keycode, you can download the sample code and its IPK file at the below link for free.

Result in the webOS TV Emulator

You can install the sample app and see the sample app result in the webOS TV emulator as below image.

Do's and Don'ts

  • Do test this sample app on your webOS TV emulator and real webOS TV.
  • Do use the JavaScript Switch State when you want to handle different action according to each keycode.
  • Don't try to find keycode of the TV power key. webOS TV does not provide it.