Remote Input

When the user pushes buttons on the remote control, these button presses will be sent over Bluetooth to the cloud connector, and then over the internet to the browser running in the cloud. From your app's point of view, these button presses will be received exactly as if the user had typed the equivalent keys on the keyboard.

Remote ButtonJavaScriptASCII Code
OKEnter13
BackEscape27
UpArrowUp38
DownArrowDown40
LeftArrowLeft37
RightArrowRight39

Key Listener

Every app should have a key down event listener like this:

document.addEventListener("keydown", async function(event) {
  switch (event.key) {
    case "Enter": enter(); break;
    case "Escape": escape(); break;
    case "ArrowUp": up(); break;
    case "ArrowDown": down(); break;    
    case "ArrowLeft": left(); break;
    case "ArrowRight": right(); break;
    default: return;
  }
  event.preventDefault();
});

How you implement the up(), down(), left(), right(), enter() and escape() functions is up to you and depends on your use case.

Note that it is not necessary to integrate with the Client Library to receive key events. It is exactly the same as how a standard web application would receive keyboard input in a normal browser. In fact, you can view your app in a desktop browser and test remote control input functionality by typing the equivalent keys.

uiReady

Typically you would initialize your Senza app like this. You can call the uiReady() function to indicate that your app has finished setting everything up and is ready to start receiving key events. For more information, see the Initialization page.

import { init, uiReady } from "senza-sdk";

window.addEventListener("load", async () => {
  try {
    await init();
    document.addEventListener("keydown", handleKeys);
    uiReady();
  } catch (error) {
    console.error(error);
  }
});

Tutorials

For a more in-depth exploration of adapting an existing app for remote control based input, see the tutorials in the Remote Control section.


What’s Next