Giter VIP home page Giter VIP logo

keycode's Introduction

keycode

Simple map of keyboard codes.

Build Status

Installation

$ component install timoxley/keycode

Example

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

API

keycode tries to make an intelligent guess as to what you're trying to discover based on the type of argument you supply.

##keycode(keycode:Event)

Returns the name of the key associated with this event.

document.body.addEventListener('keyup', function(e) {
  console.log(keycode(e)) // prints name of key
})

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

##keycode(keycode:Number)

Returns the lowercase name of a given numeric keycode.

keycode(13) // => 'enter'

##keycode(name:String)

Returns the numeric keycode for given key name.

keycode('Enter') // => 13

// keycode is not case sensitive
keycode('eNtEr') // => 13

Name Aliases

Common aliases are also supplied:

> for (var alias in keycode.aliases) { console.log(alias, keycode(keycode(alias))) }
ctl ctrl
pause pause/break
break pause/break
caps caps lock
escape esc
pgup page up
pgdn page up
ins insert
del delete
spc space

Maps

Key code/name maps are available directly as keycode.codes and keycode.names respectively.

keycode.names[13] // => 'enter'
keycode.codes['Enter'] // => 13

Credit

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

License

MIT

keycode's People

Contributors

edef1c avatar jkroso avatar kenany avatar timoxley avatar tj avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.