1.0.4 • Published 4 years ago

node-keys-down v1.0.4

Weekly downloads
4
License
ISC
Repository
github
Last release
4 years ago

node-keys-down

Check what keys are down with a simple API

installation

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.

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.

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.

const keysDown = require('node-keys-down')
keysDown.start()

// ...

console.log(keysDown.keysPressed())
1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago