Handling Input

The KreaTV IP-STB software supports input handling through standardized JavaScript DOM level 3 event model using the KeyboardEvent interface. See the key identifiers page for a listing of the remote control key identifiers.

Begin by adding an event listener and a handler function to your document:


  // Add event listener
  document.addEventListener("keydown", keyPress, false);

  ...

  function keyPress(event) {
      if (event.keyIdentifier == "MediaStop") {
          alert("You pressed stop");
      }
  }

In addition to key identifiers it is also possible to use key codes in the event handler.


  // Key code constants
  var KEY_PAUSE   = 917528;
  var KEY_STOP    = 917522;
  var KEY_UP      = 38;
  var KEY_DOWN    = 40;

  // Alternate way to add event listener
  document.onkeydown = keyPress;

  ...

  function keyPress(event) {
      switch (event.which) {
          case KEY_STOP:
              alert("You pressed stop");
              break;
          ...
      }
  }