Skip to content
Back to skills

Read Keyboard

ASecurity

Read keyboard keys and face buttons in update(). Use for keyboard movement, jumping, menus, typed text, or remapping keys, "press any key" screens (isAnyKeyPressed), including raw key codes like 'KeyW', the default key mapping (W, A, S, D for player 0, arrow keys for player 1), and making the arrow keys steer player 0 in a one-player game (keyboardLayout: 'single').

  • 17 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 7, 2026
development

Security analysis

A100/100

Scanned November 24, 2026

npx -y skills add blit386/blit386 --skill read-keyboard --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Read Keyboard?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Read Keyboard
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/blit386-read-keyboard/badge)](https://www.skillsdirectory.com/skills/blit386-read-keyboard)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: read-keyboard
description: >-
  Read keyboard keys and face buttons in update(). Use for keyboard movement, jumping, menus, typed text, or remapping
  keys, "press any key" screens (isAnyKeyPressed), including raw key codes like 'KeyW', the default key mapping (W, A,
  S, D for player 0, arrow keys for player 1), and making the arrow keys steer player 0 in a one-player game
  (keyboardLayout: 'single').
---

# Read the keyboard

Read keys and face buttons in `update()`. For player 0, W, A, S, D already map to the D-pad and Space to `BTN_A`; the
arrow keys belong to player 1 by default. A one-player game that wants the arrows too sets `keyboardLayout: 'single'`
(see One-player game below).

## Face buttons (work on keyboard and gamepad)

```js
update() {
    if (BT.isDown(BT.BTN_RIGHT, 0)) this.x += 2; // held: movement
    if (BT.isPressed(BT.BTN_A, 0)) this.jump(); // one frame: jump/fire/confirm
    if (BT.isReleased(BT.BTN_A, 0)) this.release();
}
```

Player number is `0` for a one-player game. Directions: `BT.BTN_LEFT/RIGHT/UP/DOWN`; actions: `BT.BTN_A/B/X/Y`.

## One-player game: WASD and the arrow keys

```js
configure() {
    return {
        keyboardLayout: 'single', // player 0: WASD and arrows; player 1: IJKL (engine 1.8.0+)
    };
}
```

`'single'` also stops the arrow keys scrolling the page (unless you set `isCapturingKeyboardScroll: false`). The
default, `'versus'`, keeps WASD for player 0 and the arrows for player 1 - right for a two-player keyboard game.

## Raw keys by name

Use the browser key code (`'KeyW'`, `'Space'`, `'ArrowUp'`, `'Enter'`):

```js
if (BT.isKeyDown('KeyW')) this.y -= 2; // held
if (BT.isKeyPressed('Enter')) this.start(); // one frame
if (BT.isKeyPressed('ArrowUp', 10)) this.menuUp(); // repeats every 10 ticks while held
```

## Any key (engine 1.8.0+)

For a "press any key to start" screen or an idle check, ask about the whole keyboard instead of a named key:

```js
update() {
    if (BT.isAnyKeyPressed()) this.startGame(); // any key went down this frame, even with another key held
    if (BT.isAnyKeyReleased()) this.idleTimer = 0; // the LAST held key came up: everything is up now
}
```

`BT.isAnyKeyPressed(10)` also repeats every 10 ticks while keys stay held. `isAnyKeyReleased` does not fire when one key
comes up but another is still down; use `BT.isKeyReleased(code)` for per-key releases. Gamepad version:
`BT.isAnyButtonPressed(player?)`, see `skills/read-gamepad/`.

## Typed text

```js
// In update(): BT.inputString holds the keys typed since the last update (a getter).
for (const ch of BT.inputString) {
  if (ch === '\b') {
    this.name = this.name.slice(0, -1); // Backspace deletes the last character
  } else if (ch === '\r') {
    this.submitName(); // Enter
  } else if (ch >= ' ') {
    this.name += ch; // a printable character; Tab and Escape (below space) are skipped
  }
}
```

It needs a physical keyboard (engine 1.9.0+; older engines never fill it). Touch-screen keyboards, IME input (Chinese,
Japanese, Korean) and paste do not reach it, and only plain ASCII characters arrive.

## Remap a face button

```js
BT.inputMap(0, BT.BTN_A, 'KeyZ', 'Space'); // player, button, one or more key codes
BT.inputMap(0, BT.BTN_LEFT, 'KeyA', 'ArrowLeft'); // replaces the list, so keep 'KeyA' to keep WASD working
BT.inputMapReset(); // back to the keyboardLayout's defaults
```

## Key calls

- `BT.isKeyDown(code)` / `BT.isKeyPressed(code, repeat?)` / `BT.isKeyReleased(code)` - methods. A tap shorter than one
  update tick is never `isKeyDown`, only pressed and released; use `isKeyPressed` when every tap must count.
- `BT.isAnyKeyDown()` / `BT.isAnyKeyPressed(repeat?)` / `BT.isAnyKeyReleased()` - methods, engine 1.8.0+ (whole
  keyboard).
- `BT.isDown(button, player)` / `BT.isPressed(...)` / `BT.isReleased(...)` - methods (face buttons).
- `BT.inputString` - getter (typed characters).
- `BT.inputMap(player, button, ...keys)` / `BT.inputMapReset()` - methods (players 0-1 only). `inputMapReset` restores
  the active `keyboardLayout`'s tables (engine 1.8.0+), not always the WASD / arrows split.
- `BT.DEFAULT_KEYBOARD_PLAYER1` / `BT.DEFAULT_KEYBOARD_PLAYER2` (`'versus'`) and `BT.DEFAULT_KEYBOARD_SINGLE_PLAYER1` /
  `BT.DEFAULT_KEYBOARD_SINGLE_PLAYER2` (`'single'`, engine 1.8.0+) - the default key tables, read-only, for a controls
  screen that lists the keys.

## Notes

- Read input in `update()`, not `render()` - presses, releases, and typed text are one-frame events that already reset
  by the time `render()` runs, so checking them there can silently drop taps under fast input.
- "Down" means held every frame; "Pressed" / "Released" is the single edge frame.
- Arrow keys and Space scroll the host page by default. Set `isCapturingKeyboardScroll: true` in `configure()` when your
  game maps those keys so the page does not move while the canvas is focused (`keyboardLayout: 'single'` turns it on for
  you).

See `docs/input.md`.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.