1.0.0 • Published 7 years ago

kee v1.0.0

Weekly downloads
7
License
-
Repository
-
Last release
7 years ago

kee.js

Turn keyboard events into legible key names.

Introduction

This library exists because the same few bugs show up in most websites that implement keyboard shortcuts:

  • Poor cross-OS support
  • Poor cross-browser support
  • Modifiers are sometimes ignored
  • Key handling code is unreadable and difficult to maintain

Code using kee.js will neither have any of these issues, nor ever need to consider them.

API

kee(event)

Returns a string naming the key press than generated event.

event: A KeyboardEvent with type 'keyup' or 'keydown'.

Key press string format

Key press strings consist of all held modifiers, each followed by "+", follwed by the pressed key.

A key's name is its physical label, in lower case, with spaces removed. It is not always what the press would type - for example, "shift" types nothing, and "shift+4" types "$" (on a US keyboard).

Modifiers are "ctrl", "alt", "shift", and "windows", and always appear in that order. macOS's "Command" is given as "ctrl", and its Option as "alt".

If a key press can't be identified then the string 'unidentified' is returned. This shouldn't happen except on custom hardware.