Skip to content

fix(input): a key pressed and released between two ticks is never seen #519

Open

Description

@Exeloo

Which package is this bug report for?

input

Issue description

The keyboard state is a plain held/not-held map: keydown sets inputs[code] = true and keyup sets it back to false (input-handler.ts#L96-L102). Systems only read it through getKeyStatus, once per tick.

So a key pressed and released between two ticks (a quick tap, or any tap when the tick rate is low or the tab was throttled) is never seen by any system. There is also no "just pressed" state: every example game that reacts to one press (pong and breakout menus, flappy-bird's flap, tic-tac-toe, the scene switch in basics/scenes) carries its own justPressed helper that remembers the previous tick's state, and that helper misses the same taps.

Found while remaking the example games (NanoForge-dev/examples#18, shared/input/just-pressed.ts).

Code sample

// a system at tickRate 10: tap Space quickly (down and up within 100 ms)
if (ctx.input.getKeyStatus(InputEnum.Space)) flap(); // never runs

Versions

  • @nanoforge-dev/input 3.0.0
  • Chrome, Linux

Issue priority

Medium (should be fixed soon)

I have tested this issue on a development release

ed8c7e0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingmodules:inputRelated to Input library

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions