Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

game-keyboard

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

game-keyboard

Check current state of keyboard keys in the browser. Suitable for games.

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
Maintainers
1
Weekly downloads
 
Created
Source

game-keyboard

Check current state of keyboard keys in the browser. Suitable for games.

Example

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

Constructor

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.

Install

With npm do:

npm install game-keyboard

License

MIT. See the file LICENSE.TXT.

Keywords

FAQs

Package last updated on 20 Jan 2015

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc