Keyboard
The Keyboard
class is a singleton class that handles keyboard input.
info
Prefer to get the unique instance of this service from the ServiceContainer
like:
const keyboard = ServiceContainer.keyboard;
Getters
instance
- Type:
Keyboard
Get the instance of keyboard service.
Methods
isDown
prototype
isDown(key: string): boolean;
Check if a key is down.
Parameters
key
- Type:
string
- The key to check (it's an
event.code
fromKeyboardEvent
).
- Type:
Return
boolean
- true
if the key is down, false
otherwise.
Example
ServiceContainer.Keyboard.isDown('KeyA');
isUp
prototype
isUp(key: string): boolean;
Check if a key is up.
Parameters
key
- Type:
string
- The key to check (it's an
event.code
fromKeyboardEvent
).
- Type:
Return
boolean
- true
if the key is up, false
otherwise.
Example
ServiceContainer.Keyboard.isUp('KeyA');
isJustDown
prototype
isJustDown(key: string): boolean;
Check if a key is just down during the current frame.
Parameters
key
- Type:
string
- The key to check (it's an
event.code
fromKeyboardEvent
).
- Type:
Return
boolean
- true
if the key is just down down, false
otherwise.
Example
ServiceContainer.Keyboard.isJustDown('KeyA');
isJustUp
prototype
isJustUp(key: string): boolean;
Check if a key is just up during the current frame.
Parameters
key
- Type:
string
- The key to check (it's an
event.code
fromKeyboardEvent
).
- Type:
Return
boolean
- true
if the key is just up, false
otherwise.
Example
ServiceContainer.Keyboard.isJustUp('KeyA');