A lightweight JavaScript library for interpreting event key and character codes across browsers.
npm install keycoder[david-url]: https://david-dm.org/nbeach/keycoder
[david-image]: https://img.shields.io/david/nbeach/keycoder.svg
[david-dev-url]: https://david-dm.org/nbeach/keycoder#info=devDependencies
[david-dev-image]: https://david-dm.org/nbeach/keycoder/dev-status.svg
[david-peer-url]: https://david-dm.org/nbeach/keycoder#info=peerDependencies
[david-peer-image]: https://david-dm.org/nbeach/keycoder/peer-status.svg
[coveralls-url]: https://coveralls.io/r/nbeach/keycoder/
[coveralls-image]: https://img.shields.io/coveralls/nbeach/keycoder.svg
A lightweight JavaScript library for interpreting event key and character codes across browsers. Keycoder implements UMD for CommonJS, AMD, and global based loading support.
Keycoder is released under the MIT license.
* Keycoder
* .key : object
* .toCharacter(keyCode, shift) ⇒ string | null
* .charCodeToCharacter(charCode) ⇒ string | null
* .eventToCharacter(event) ⇒ string | null
* .fromCharacter(character) ⇒ Key | null
* .fromKeyCode(keyCode) ⇒ Key | null
* .fromCharCode(charCode) ⇒ Key | null
* .fromEvent(event) ⇒ Key | null
* .allKeys() ⇒ Array.<Key>
Kind: static property of Keycoder
Properties
| Name | Type |
| --- | --- |
| BACKSPACE | Key |
| TAB | Key |
| ENTER | Key |
| SHIFT | Key |
| CONTROL | Key |
| ALT | Key |
| PAUSE | Key |
| BREAK | Key |
| CAPS_LOCK | Key |
| ESCAPE | Key |
| WINDOWS | Key |
| COMMAND | Key |
| OPTION | Key |
| PRINT_SCREEN | Key |
| NUM_LOCK | Key |
| MAC_NUM_LOCK | Key |
| SCROLL_LOCK | Key |
| PAGE_UP | Key |
| PAGE_DOWN | Key |
| END | Key |
| HOME | Key |
| LEFT_ARROW | Key |
| UP_ARROW | Key |
| RIGHT_ARROW | Key |
| DOWN_ARROW | Key |
| INSERT | Key |
| DELETE | Key |
| NUMPAD_0 | Key |
| NUMPAD_1 | Key |
| NUMPAD_2 | Key |
| NUMPAD_3 | Key |
| NUMPAD_4 | Key |
| NUMPAD_5 | Key |
| NUMPAD_6 | Key |
| NUMPAD_7 | Key |
| NUMPAD_8 | Key |
| NUMPAD_9 | Key |
| NUMPAD_MULTIPLY | Key |
| NUMPAD_PLUS | Key |
| NUMPAD_MINUS | Key |
| NUMPAD_DECIMAL | Key |
| NUMPAD_DIVIDE | Key |
| NUMPAD_MIDDLE | Key |
Keycoder string | null - The character for the keycode and shift state. Null if the key is not a printable character. | Param | Type | Description |
| --- | --- | --- |
| keyCode | number | An IE or Mozilla key code |
| shift | boolean | The shift key state. A value of true indicates it is pressed, false that it is not |
Keycoder string | null - Returns the character for the character code. Null if the key is not a printable character. | Param | Type | Description |
| --- | --- | --- |
| charCode | number | An ASCII character code |
Keycoder string | null - - The character pressed in the key event. Null if the key pressed is not a printable character, or the event is not a key event. | Param | Type | Description |
| --- | --- | --- |
| event | number | A keydown, keyup, or keypress event object |
Keycoder Key | null - A Key object. Null if no key is associated with the provided code. | Param | Type |
| --- | --- |
| character | string |
Keycoder Key | null - A Key object. Null if no key is associated with the provided code. | Param | Type | Description |
| --- | --- | --- |
| keyCode | number | A IE or Mozilla key code |
Kind: static method of Keycoder
Returns: Key | null - A Key object. Null if no key is associated with the provided code.
| Param | Type | Description |
| --- | --- | --- |
| charCode | number | An ASCII character code |
Kind: static method of Keycoder
Returns: Key | null - A Key object. Null if no key was pressed in the provided event.
| Param | Type | Description |
| --- | --- | --- |
| event | object | A keydown, keyup, or keypress event object |
Keycoder Array.<Key> - An array of Key objects for all keys | Name | Type | Description |
| --- | --- | --- |
| names | Array.<string> | Names that the key is called. Ex. "BACKSPACE", "INSERT" |
| keyCode.ie | number | IE key code |
| keyCode.mozilla | number | Mozillia key code |
| character | string | null | Key character |
| charCode | number | null | ASCII character code |
| shift.character | string | null | Key shift character |
| shift.charCode | number | null | Shift ASCII character code |
* Key
* new Key()
* .isPrintableCharacter() ⇒ boolean
* .hasCharCode() ⇒ boolean
* .hasDistinctShiftCharacter() ⇒ boolean
* .equals(other) ⇒ boolean
Key boolean - If the key is a printable character Key boolean - If the key has a character code Key boolean - If the key's character and shift character are different Key boolean - True if the key and the compared key/code are the same key | Param | Type | Description |
| --- | --- | --- |
| other | Key | number | A Key object or key code |