# inp

> State-based input library for the browser.

Latest version **1.35.0** (published 2022-02-18) · ISC license · 0 weekly downloads

## Install

```sh
npm install inp
pnpm add inp
yarn add inp
bun add inp
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.35.0 |
| Published | 2022-02-18 |
| First published | 2022-02-11 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | spidunno |
| Maintainers | spidunno |

## Links

- npm: https://www.npmjs.com/package/inp
- Repository: https://github.com/spidunno/inp
- Homepage: https://github.com/spidunno/inp#readme
- Issues: https://github.com/spidunno/inp/issues
- npm.io page: https://npm.io/package/inp

## Recent versions

- 1.35.0 (latest) — 2022-02-18
- 1.34.0 — 2022-02-18
- 1.33.0 — 2022-02-18
- 1.32.0 — 2022-02-18
- 1.30.0 — 2022-02-18
- 1.29.0 — 2022-02-18
- 1.28.0 — 2022-02-18
- 1.27.0 — 2022-02-18
- 1.26.0 — 2022-02-18
- 1.25.0 — 2022-02-18
- 1.24.0 — 2022-02-18
- 1.23.0 — 2022-02-18
- 1.20.0 — 2022-02-18
- 1.19.0 — 2022-02-18
- 1.18.0 — 2022-02-17
- … 18 more at https://npm.io/package/inp/versions

## README

# Inp
## State based input library for the browser.
---
### Installation:
Either install with npm or use a CDN such as unpkg (eg. `https://unpkg.com/inp/index.js`).
### Usage:
```js
import InputReader from 'path/to/inp.js';

let input = InputReader();
const frameRate = 1000/60;
function main() {
	/* input.down tells you if that button is down in the current frame / step. */
	if(input.down('a')) console.log('Key "A" pressed!');
	/* input.up does much the same as input.down but instead tells you if the button was released this frame */
	if(input.up('MouseLeft')) console.log('Left Mouse Button was released this timestep.');
	/* use input.mouse to get the position of the mouse this frame */
	console.log(input.mouse('x'), input.mouse('y'));
	console.log(input.mouse().x, input.mouse('both').y);
	/* and input.step at the end of you main loop to step forward. Nothing will work unless you do this. */
	input.step();
	setTimeout(main, frameRate);
}
main();
```
### API:
#### `InputReader.down(key: string): boolean`
Takes in a string that is either a valid `event.key`, `"MouseLeft"`, `"MouseRight"`, `"MouseMiddle"`, `"MouseBack"`, or `"MouseForward"`. Returns a boolean of whether it's  down.
___
#### `InputReader.up(key: string): boolean`
Similar `InputReader.down`, tells you if a key has been released this timestep, takes the same arguments as `InputReader.down`.
___
#### `InputReader.mouse(which?: string): number | Object`
Takes in a string that is either `"x"`, `"y"`,  or `"both"`, returns the X position of the mouse, the Y position of the mouse, or `{x: <number>, y: <number>}`, respectively. If no argument is given it defaults to `"both"`.
___
#### `InputReader.step(): void`
Steps forward once and updates everything. Required to be called before any inputs can be read correctly.
___
(:

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