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, SpaceLeftShift, RightShift, LeftControl, RightControl, LeftAlt, RightAlt, LeftOS, RightOSInsert, Home, PageUp, Delete, End, PageDown, Left, Up, Right, DownF1 to F12: for the function keysLA to LZ: for standard latin letter keysD0 to D9: for digits 0 to 9 on the main keyboard sectionN0 to N9: for digits 0 to 9 on the number padN/, N*, N-, N+, NEnter, ND: for the operators, enter and decimal separator keys on the number padUnknown: 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 keyIdstring a well known Refugee Lib key ID or a printable char
keyStaterlKeys.keyState the key state to modify
stateCodenumber 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 keyStaterlKeys.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 staterlKeys.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 sourceIdstring the browser-specific key id from a raw dom keyboard event
sourceLocationnumber 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 keyIdstring a well known Refugee Lib key ID or a printable char
keyStaterlKeys.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 keyIdstring a well known Refugee Lib key ID or a printable char
keyStaterlKeys.keyState the key state to modify
stateCodenumber 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))