1.1.1 • Published 8 years ago

keycoder v1.1.1

Weekly downloads
1,167
License
MIT
Repository
github
Last release
8 years ago

Keycoder

npm version Build Status Coverage Status Dependency Status devDependency Status

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.

Modules

Classes

Keycoder

Keycoder.key : object

An object containing references to all named keys.

Kind: static property of Keycoder
Properties

NameType
BACKSPACEKey
TABKey
ENTERKey
SHIFTKey
CONTROLKey
ALTKey
PAUSEKey
BREAKKey
CAPS_LOCKKey
ESCAPEKey
WINDOWSKey
COMMANDKey
OPTIONKey
PRINT_SCREENKey
NUM_LOCKKey
MAC_NUM_LOCKKey
SCROLL_LOCKKey
PAGE_UPKey
PAGE_DOWNKey
ENDKey
HOMEKey
LEFT_ARROWKey
UP_ARROWKey
RIGHT_ARROWKey
DOWN_ARROWKey
INSERTKey
DELETEKey
NUMPAD_0Key
NUMPAD_1Key
NUMPAD_2Key
NUMPAD_3Key
NUMPAD_4Key
NUMPAD_5Key
NUMPAD_6Key
NUMPAD_7Key
NUMPAD_8Key
NUMPAD_9Key
NUMPAD_MULTIPLYKey
NUMPAD_PLUSKey
NUMPAD_MINUSKey
NUMPAD_DECIMALKey
NUMPAD_DIVIDEKey
NUMPAD_MIDDLEKey

Keycoder.toCharacter(keyCode, shift) ⇒ string | null

Kind: static method of Keycoder
Returns: string | null - The character for the keycode and shift state. Null if the key is not a printable character.

ParamTypeDescription
keyCodenumberAn IE or Mozilla key code
shiftbooleanThe shift key state. A value of true indicates it is pressed, false that it is not

Keycoder.charCodeToCharacter(charCode) ⇒ string | null

Kind: static method of Keycoder
Returns: string | null - Returns the character for the character code. Null if the key is not a printable character.

ParamTypeDescription
charCodenumberAn ASCII character code

Keycoder.eventToCharacter(event) ⇒ string | null

Kind: static method of Keycoder
Returns: 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.

ParamTypeDescription
eventnumberA keydown, keyup, or keypress event object

Keycoder.fromCharacter(character) ⇒ Key | null

Kind: static method of Keycoder
Returns: Key | null - A Key object. Null if no key is associated with the provided code.

ParamType
characterstring

Keycoder.fromKeyCode(keyCode) ⇒ Key | null

Kind: static method of Keycoder
Returns: Key | null - A Key object. Null if no key is associated with the provided code.

ParamTypeDescription
keyCodenumberA IE or Mozilla key code

Keycoder.fromCharCode(charCode) ⇒ Key | null

Maps an ASCII character code to a Key object

Kind: static method of Keycoder
Returns: Key | null - A Key object. Null if no key is associated with the provided code.

ParamTypeDescription
charCodenumberAn ASCII character code

Keycoder.fromEvent(event) ⇒ Key | null

Maps a keypress, keydown, or keyup event object to a key

Kind: static method of Keycoder
Returns: Key | null - A Key object. Null if no key was pressed in the provided event.

ParamTypeDescription
eventobjectA keydown, keyup, or keypress event object

Keycoder.allKeys() ⇒ Array.<Key>

Kind: static method of Keycoder
Returns: Array.<Key> - An array of Key objects for all keys

Key

Kind: global class
Internal:
Properties

NameTypeDescription
namesArray.<string>Names that the key is called. Ex. "BACKSPACE", "INSERT"
keyCode.ienumberIE key code
keyCode.mozillanumberMozillia key code
characterstring | nullKey character
charCodenumber | nullASCII character code
shift.characterstring | nullKey shift character
shift.charCodenumber | nullShift ASCII character code

new Key()

A representation of a keyboard key. This class cannot be instantiated manually. All instances are generated by the Keycoder module.

key.isPrintableCharacter() ⇒ boolean

Kind: instance method of Key
Returns: boolean - If the key is a printable character

key.hasCharCode() ⇒ boolean

Kind: instance method of Key
Returns: boolean - If the key has a character code

key.hasDistinctShiftCharacter() ⇒ boolean

Kind: instance method of Key
Returns: boolean - If the key's character and shift character are different

key.equals(other) ⇒ boolean

Kind: instance method of Key
Returns: boolean - True if the key and the compared key/code are the same key

ParamTypeDescription
otherKey | numberA Key object or key code