2.2.1 • Published 2 years ago

keycode v2.2.1

Weekly downloads
975,592
License
MIT
Repository
github
Last release
2 years ago

keycode

Simple map of keyboard codes.

Build Status

Installation

npm

$ npm install keycode

component

$ 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,keycodecurrently 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 down
ins insert
del delete
spc space

keycode.isEventKey(event: Event, nameOrCode: String | Number)

Tests if an keyboard event against a given name or keycode. Will return true if the event matches the given name or keycode, false otherwise.

// assume event is an keydown event with key 'enter'
keycode.isEventKey(event, 'enter') // => true
keycode.isEventKey(event, 'down') // => false

keycode.isEventKey(event, 13) // => true
keycode.isEventKey(event, 40) // => false

Maps

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

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

Credit

 project  : keycode
 repo age : 3 years, 8 months
 active   : 29 days
 commits  : 66
 files    : 13
 authors  :
    49	Tim Oxley        74.3%
     4	jkroso           6.1%
     3	Amir Abu Shareb  4.5%
     1	Greg Reimer      1.5%
     1	Kenan Yildirim   1.5%
     1	Abel Toledano    1.5%
     1	Sam              1.5%
     1	TJ Holowaychuk   1.5%
     1	Yoshua Wuyts     1.5%
     1	Nathan Zadoks    1.5%
     1	Brenton Simpson  1.5%
     1	Brian Noguchi    1.5%
     1	Gilad Peleg      1.5%

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

License

MIT

vue-lol@alexghi/material-ui@instructure/ui-pagination@instructure/ui-buttons@instructure/ui-alerts@instructure/ui-tree-browser@instructure/ui-utils@instructure/ui-tabs@instructure/ui-menu@instructure/ui-number-inputcrehana-material-uidezign-system@rock-kit/ui-a11y@rock-kit/ui-a11y-content@rock-kit/ui-a11y-utils@rock-kit/ui-alerts@rock-kit/ui-buttons@rock-kit/ui-checkbox@rock-kit/ui-file-drop@rock-kit/ui-forms@rock-kit/ui-menu@rock-kit/ui-number-input@rock-kit/ui-overlays@rock-kit/ui-popover@rock-kit/ui-selectable@rock-kit/ui-tabs@rock-kit/ui-test-queries@rock-kit/ui-tree-browser@rock-kit/ui-utilsgraphql-playground-react-authwmvuiassrmuse-ui-clientreact17-swipeable-views-utils@deboxsoft/webapp-components@umidbekkarimov/material-uivideoyj.jszennvideojs-yj@temporg/ui-a11y-utils@temporg/ui-utils@saber71/gl-render2d@saber71/util-code@entercash/ec-ui-componentsko-editorhexidave-material-ui-corehexidave-material-ui-nexthexidave-material-ui-old@okanselami/design-systemsmile-xin-amisdebox-web-componentreax-formreax-cmsfastamisxprst-comreact-bootstrap-zoqer@infinitebrahmanuniverse/nolb-keycatj-react-modal-dialogcaozhengqianformsy-material-ui-customizedreact-swipeable-view-utilsunless-material-ui@everything-registry/sub-chunk-2012datav-amis@unless.com/material-ui-core@opuscapita/slate-react@opuscapita/react-rich-editorsddy-uireact-keystackreact-keycodedev136-video.jsreact-lite-layeredreact-lite-textboxsimple-react-typescript-appshulive-uidrive-video-jssemsis-controlssearch-with-your-keyboardseanthchao-testshaz-runnableshadertoy-exportsidekick-workersimple-test-library-2dub-uisinoui-componentssixbee-material-uisnake-gosnapmaker-lubansparta-material-uieks-uienhanced-video.jsstatsd-keystrokesemp-material-ui-pickersdoctorlink-design-systemdoctorlinkdsreact-popover-controlreact-portland-uireact-pure-uireact-material-ui-multiselectreact-modal-dialog
2.2.1

2 years ago

2.2.0

6 years ago

2.1.9

7 years ago

2.1.8

7 years ago

2.1.7

8 years ago

2.1.6

8 years ago

2.1.5

8 years ago

2.1.4

8 years ago

2.1.2

8 years ago

2.1.1

8 years ago

2.1.0

9 years ago

2.0.0

9 years ago

1.0.1

9 years ago

1.0.0

10 years ago

0.3.0

11 years ago

0.2.3

11 years ago

0.2.2

11 years ago