https://github.com/fabiosantoscode/keys-down
Check what keys are down with a simple API
https://github.com/fabiosantoscode/keys-down
Last synced: 10 months ago
JSON representation
Check what keys are down with a simple API
- Host: GitHub
- URL: https://github.com/fabiosantoscode/keys-down
- Owner: fabiosantoscode
- License: mit
- Created: 2018-09-21T18:21:17.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-02T12:12:07.000Z (about 3 years ago)
- Last Synced: 2025-03-13T07:39:48.117Z (11 months ago)
- Language: JavaScript
- Size: 253 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# node-keys-down
Check what keys are down with a simple API
## installation
```bash
npm install node-keys-down
```
## require('node-keys-down').start()
Start detecting keyboard activity. Call this method before the others.
It returns a function that ends detecting keyboard activity.
```javascript
const keysDown = require('node-keys-down')
const end = keysDown.start()
// ... your code
end()
```
## require('node-keys-down').isPressed(key)
Returns `true` if `key` is pressed. The key code looks like [what you might see in `event.key`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values).
```javascript
const keysDown = require('node-keys-down')
keysDown.start()
// ...
const playerMovingLeft = keysDown.isPressed('ArrowLeft')
const playerRunning = keysDown.isPressed('Shift')
const playerShooting = keysDown.isPressed(' ')
const playerUsing = keyDown.isPressed('e') || keysDown.isPressed('E')
```
## require('node-keys-down').keysPressed()
Returns an array with the names of all keys which are currently pressed.
```javascript
const keysDown = require('node-keys-down')
keysDown.start()
// ...
console.log(keysDown.keysPressed())
```