Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Convert between keyboard keycodes and keynames and vice versa.
JavaScript CSS Other
Tag: 0.0.2

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
examples
test
.gitignore
Makefile
Readme.md
component.json
index.js

Readme.md

keycode

Simple map of keyboard codes.

Installation

$ component install timoxley/keycode

Example

var keycode = require('keycode');
document.addEventListener('keydown', function(e) {
  console.log("You pressed", keycode(e.keyCode))
})

API

The keycode method responds differently depending on whether you're looking up a keycode or a keyname.

keycode(keycode:Number)

Returns name for given numeric keycode.

  console.log(keycode(13)) // => 'Enter'

keycode(name:String)

Returns numeric keycode for given key name.

  console.log(keycode('Enter')) // => 13

KeyCode and KeyName maps are available directly as keycode.keyCodes and keycode.keyNames respectively.

  console.log(keycode.keyCodes[13]) // => 'Enter'
  console.log(keycode.keyNames['Enter']) // => 13

Event Support

Due to the keypress event being weird,keycodecurrently does not support the keypress event, but this should not be an issue as keydown and keyup work perfectly fine.

Credit

Original code lifted from http://jsfiddle.net/vWx8V/ via http://stackoverflow.com/questions/5603195/full-list-of-javascript-keycodes

License

MIT

Something went wrong with that request. Please try again.