# @arcade2d/controls

> Game control input library.

Latest version **0.1.2** (published 2021-06-06) · 0 weekly downloads

## Install

```sh
npm install @arcade2d/controls
pnpm add @arcade2d/controls
yarn add @arcade2d/controls
bun add @arcade2d/controls
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2021-06-06 |
| First published | 2021-06-06 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 13.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | martywallace |

## Links

- npm: https://www.npmjs.com/package/@arcade2d/controls
- npm.io page: https://npm.io/package/@arcade2d/controls

## Dependencies (1)

- [typescript](https://npm.io/package/typescript.md) ^4.3.2

## Recent versions

- 0.1.2 (latest) — 2021-06-06
- 0.1.1 — 2021-06-06
- 0.1.0 — 2021-06-06

## README

# Controls

Input detection components for browser-based game controls.

## Installation

```bash
$ yarn add @arcade2d/controls
```

## Examples

### Keyboard Input

```typescript
import {
  KeyboardInput,
  KeyboardInputEvent,
  KeyboardState,
} from '@arcade2d/controls';

// Define keyboard input manager instance.
const keyboard = new KeyboardInput(document);

// Handle key press and release handlers.
keyboard.onKeyPress((event: KeyboardInputEvent) =>
  console.log('press', event.key),
);
keyboard.onKeyRelease((event: KeyboardInputEvent) =>
  console.log('release', event.key),
);

// Check keyboard state during a loop.
setInterval(() => {
  const state: KeyboardState = keyboard.getState();

  if (state.isDown('a')) {
    console.log('a is held down');
  }
}, 16);
```

---
_Source: https://npm.io/package/@arcade2d/controls · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
