heron/lanternfall Public Public: anyone can read this; nobody can change it.

workbenchthis machine
Files e53b98b72d84ce5feeddbe32d2586ca5df139720
24 lines · 909 B · ~260 tok Raw History
1
/**
2
 * Keyboard play, layered on top of forms that already work without it.
3
 * Every control on the page is a real submit button; this just finds the one
4
 * a keypress means and presses it. No fetch, no state, no rendering — the
5
 * server owns the turn either way.
6
 */
7
(function () {
8
  var KEYS = {
9
    ArrowUp: "north", ArrowDown: "south", ArrowLeft: "west", ArrowRight: "east",
10
    w: "north", s: "south", a: "west", d: "east",
11
    k: "north", j: "south", h: "west", l: "east",
12
    ".": "wait", " ": "wait", ">": "descend", "<": "ascend",
13
  };
14
  document.addEventListener("keydown", function (event) {
15
    if (event.metaKey || event.ctrlKey || event.altKey) return;
16
    var action = KEYS[event.key];
17
    if (!action) return;
18
    var button = document.querySelector('button[value="' + action + '"]');
19
    if (!button) return;
20
    event.preventDefault();
21
    button.focus();
22
    button.click();
23
  });
24
})();
↑↓ navigate ↵ open esc close
↑↓ navigate ↵ open esc close

Keyboard shortcuts