New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

vkeys

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vkeys

map e.keyCode to vkey string

latest
Source
npmnpm
Version
1.2.0
Version published
Weekly downloads
199
-1.97%
Maintainers
1
Weekly downloads
 
Created
Source

vkeys

problem

some browsers have got an e.key attribute that is submitted with keydown and keyup events. chrome (and other browsers) does not have a e.key attribute. there are also inconsistencies between different browsers.

solution

@chrisdickinson initiated a project vkey to collect the different definitions and merge them into a unified definition. for code that can not handle spaces, or wants less clutter, this transformation might be useful.

this module transforms the vkey definition, and removes the following clutter:

  • spaces
  • < and >
  • -
  • runs toLowerCase()

the output is a static key mapping file (without dynamic edge cases): vkeys.js

usage

install

npm install vkeys

use

var vkeys = require('./vkeys');

window.addEventListener('keydown', function(e) {
  console.log(vkeys[e.keyCode])
});

api

vkeys

Object with {code : key} pairs.

{
  0: 'unk',
  ...
  8: 'backspace',
  9: 'tab',
  12: 'clear',
  13: 'enter',
  ...
  254: 'clear'
}

see: vkeys.js

vkeys.getKey(code)

return the key for the given code.

var key = vkeys.getKey(60);
assert.equal(key, '<');

vkeys.findCode(key)

returns the first code that matches the key.

var code = vkeys.findCode('space');
assert.equal(code, 32);

vkeys.findAllCodes(key)

returns an Array of code's that match the key.

var code = vkeys.findAllCodes('meta');
// code equals [91, 92, 223, 224]

build

  • get the latest vkey module: npm install --save-dev vkey
  • run the build: npm run build

test

npm install -g browserify testling
npm run test

license

MIT

Keywords

keyCode

FAQs

Package last updated on 20 Feb 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