Namespace: rlKeys

rlKeys

Keyboard input translation and state management for rlEngine.

A project using Refugee Lib should usually only use rlInputEvent.getKeyState (if it needs to query the keyboard state directly) or use the events it gets in a call of rlEngine.onInputEvent or a combination of both.

Refugee Lib refers to "well known" keys by the following (string) IDs:

  • Esc, PrintScreen, ScrollLock, Pause, Tab, CapsLock, NumLock, Backspace, Enter, Space
  • LeftShift, RightShift, LeftControl, RightControl, LeftAlt, RightAlt, LeftOS, RightOS
  • Insert, Home, PageUp, Delete, End, PageDown, Left, Up, Right, Down
  • F1 to F12 : for the function keys
  • LA to LZ : for standard latin letter keys
  • D0 to D9 : for digits 0 to 9 on the main keyboard section
  • N0 to N9 : for digits 0 to 9 on the number pad
  • N/, N*, N-, N+, NEnter, ND : for the operators, enter and decimal separator keys on the number pad
  • Unknown : for keypresses which produce character input where the source key is not "well known" (which is true for most language-specific symbols and letters and depends on the system-level keyboard layout settings)

If a key event produces printable character input, regardless of whether the key is "well known" or not to Refugee Lib, that printable character will be provided by rlEngine.onInputEvent in a property named printableChar on the currentEvent parameter.

Members

(private, static, constant) unknownId

Default Value:
  • Unknown

Methods

(static) clearKeyStateBit(keyId, keyState, stateCode) → {rlKeys.keyState}

Clear a bit of a given keyId in a given keyState.

Parameters:
Name Type Description
keyId string

a well known Refugee Lib key ID or a printable char

keyState rlKeys.keyState

the key state to modify

stateCode number

special code for internal key state magic (used by rlEngine to create a logical link between a keydown, a keypress and a keyup dom event to be able to internally remember an otherwise unknown physical key state)

Returns:

the modified key state

Type
rlKeys.keyState

(static) clearWholeKeyState(keyState) → {rlKeys.keyState}

Clear all individual key state bits in a given keyState.

Parameters:
Name Type Description
keyState rlKeys.keyState

the state to modify

Returns:

the modified key state

Type
rlKeys.keyState

(static) cloneKeyState(state) → {rlKeys.keyState}

Create a copy of a given key state.

Parameters:
Name Type Description
state rlKeys.keyState
Returns:
Type
rlKeys.keyState

(static) createEmptyKeyState() → {rlKeys.keyState}

Create a key state object where all individual key states are "not down".

Returns:
Type
rlKeys.keyState

(static) getKeyId(sourceId, sourceLocation) → {string}

Get the Refugee Lib key ID for the given raw keyboard event ids.

Parameters:
Name Type Description
sourceId string

the browser-specific key id from a raw dom keyboard event

sourceLocation number

the browser-specific location from a raw dom keyboard event

Returns:

a Refugee Lib key ID

Type
string

(static) getKeyStateBit(keyId, keyState) → {boolean}

Test if the bit for a given keyId is set in a given keyState.

Parameters:
Name Type Description
keyId string

a well known Refugee Lib key ID or a printable char

keyState rlKeys.keyState

the key state to examine

Returns:

true if the bit is set, false if it is not

Type
boolean

(static) getUnknownKeyId() → {string}

Get the id which is used for character input which originates from an unknown physical source key.

Returns:
Type
string

(static) setKeyStateBit(keyId, keyState, stateCode) → {rlKeys.keyState}

Set a bit of a given keyId in a given keyState.

Parameters:
Name Type Description
keyId string

a well known Refugee Lib key ID or a printable char

keyState rlKeys.keyState

the key state to modify

stateCode number

special code for internal key state magic (used by rlEngine to create a logical link between a keydown, a keypress and a keyup dom event to be able to internally manage an otherwise unknown physical key state)

Returns:

the modified key state

Type
rlKeys.keyState

Type Definitions

keyState

(currently internally implemented as a Uint32Array (implementation may change if necessary))