
Security News
Rspack Introduces Rslint, a TypeScript-First Linter Written in Go
Rspack launches Rslint, a fast TypeScript-first linter built on typescript-go, joining in on the trend of toolchains creating their own linters.
game-keyboard
Advanced tools
Check current state of keyboard keys in the browser. Suitable for games.
Check current state of keyboard keys in the browser. Suitable for games.
var Keyboard = require("game-keyboard");
var keyMap = require("game-keyboard/key_map")["US"];
var keyboard = new Keyboard(keyMap);
// with no keys pressed
keyboard.isPressed("up"); // returns false
keyboard.consumePressed("up"); // returns false
// start pressing up arrow
keyboard.isPressed("up"); // returns true
keyboard.consumePressed("up"); // returns true
// continuing to press up arrow
keyboard.isPressed("up"); // returns true
keyboard.consumePressed("up"); // returns false
The constructor takes a keymap, which is an object that maps keyboard codes (e.keyCode) to human-readable names.
The human-readable names in the keymap are what you use as the argument to isPressed
and consumePressed
.
This library comes with a "US" keymap in key_map.js
. I'll happily accept contributions for keymaps of other locales.
isPressed(key)
Test if a key is currently pressed.
Accepts a key name that is specified in the keymap that was given to the constructor.
consumePressed(key)
Test if a key is currently pressed, and makes the key look not pressed to subsequent calls of consumePressed
.
To make the key look pressed again, the key must be released and re-pressed. This does not affect how isPressed
sees the key.
This is useful for when you want to do some action only the first time a key is pressed, but not every frame that it is held down. For example: entering text.
Accepts a key name that is specified in the keymap that was given to the constructor.
With npm do:
npm install game-keyboard
MIT. See the file LICENSE.TXT.
[0.1.0] - 2015-01-20
FAQs
Check current state of keyboard keys in the browser. Suitable for games.
The npm package game-keyboard receives a total of 2 weekly downloads. As such, game-keyboard popularity was classified as not popular.
We found that game-keyboard demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Rspack launches Rslint, a fast TypeScript-first linter built on typescript-go, joining in on the trend of toolchains creating their own linters.
Security News
Hacker Demonstrates How Easy It Is To Steal Data From Popular Password Managers
Security News
Oxlint’s new preview brings type-aware linting powered by typescript-go, combining advanced TypeScript rules with native-speed performance.