Skip to main content
ejGames turns the keyboard and the controller into actions, the same for both: The controller’s Guide button always opens ejGames’ quick menu. F5, F11, Ctrl + F, Ctrl + , , Ctrl + P and Ctrl + K are launcher shortcuts and do not reach your theme as actions. You do not have to work out what is above or to the right. The kit has spatial navigation in focus.js.
  1. Mark everything that can be chosen with data-focus. The two buttons in the bar already have it in the HTML. Add it to the card and to the empty library button:
  2. Create the focus and connect it to the actions. Add this at the top of main.js:
    and, after ready():
  3. Show the focus in CSS. The focused element has the class is-focused:
  4. Make sure something is always focused. At the end of pintar(), after keyed(…):
    with const idEnfocado = foco.current?.dataset.id; at the start of pintar().
How it works:
  • bindNav(focus, { action: function }): the arrows move focus and accept clicks the focused element (with its sound). Your functions run first. If one returns false, the action is not treated as handled. For back, that means ejGames handles it (it closes whatever it has open and, in Big Picture, opens the quick menu).
  • foco.current is the focused element. foco.focus(el) focuses a specific one and foco.first(container) focuses the first in a container. With { silent: true } it makes no sound, and with { noScroll: true } it does not scroll.
  • ejg.game.favorite(id) toggles the favorite (or sets it if you pass true/false). You do not need to repaint by hand: the change arrives through library.onChange and the card updates itself.
  • data-focus-group (on #rejilla) remembers the last focused element of the group. If you go up to the bar and come back down, you return to the same cover.
  • With the mouse, passing over an element focuses it, and leaving removes the mark, so it does not stay stuck. With a controller the cursor is hidden.

The hint bar

hints() draws the controls with the symbols of the device in use: A B X Y with an Xbox controller, ✕ ○ □ △ with a PlayStation one, Enter, Esc, E, F with a keyboard. It changes on its own when you change device:
You can change the texts later with pistas.set([...]). The <html> element carries data-input="mouse|keyboard|gamepad", so hiding the bar with the mouse is pure CSS:
Try it now with the arrows, Enter and F (favorite).