Skip to content

ES2015 library with constants to check if Key.is(...keys) or Key.isNot(...keys) - nothing more.

License

Notifications You must be signed in to change notification settings

alienfast/key.js

Repository files navigation

NPM version Build Status

key.js

ES2015 library with constants to check if Key.is(...keys) or Key.isNot(...keys) - nothing more.

Installation

npm install --save key.js

Usage

import {Key, Keycodes} from 'key.js'

Key

The primary class for keycode checking

Key.is(ev, ...keycodes)

Returns true if keycode is any of the given keycodes

if (Key.is(ev, Keycodes.DOWN, Keycodes.ESC)) {
  // do something
}

Key.isNot(ev, ...keycodes)

Returns true if keycode is not any of the given keycodes

if (Key.isNot(ev, Keycodes.ENTER, Keycodes.TAB)) {
  // do something
}

Key.toCode(ev)

Returns (ev.keyCode || ev.which)

Keycodes

Switch example

switch (Key.toCode(ev)) {
  case Keycodes.ENTER:
  case Keycodes.TAB:
    // do something
    break
  case Keycodes.LEFT:
  case Keycodes.UP:
  case Keycodes.RIGHT:
  case Keycodes.DOWN:
  {
    // do something
    break
  }
}

About

ES2015 library with constants to check if Key.is(...keys) or Key.isNot(...keys) - nothing more.

Resources

License

Stars

Watchers

Forks

Packages

No packages published