KeyMap
⚠️
This page is under construction.
KeyMap is responsible for storing and manipulating keyboard bindings for different game actions.
Public Methods
setKeyBinding
Set (or overwrite) the key binding for a specific action.
game.keyMap.setKeyBinding(KeyBindingType.skipAction, " ");
// Or bind **multiple** keys at once
game.keyMap.setKeyBinding(KeyBindingType.skipAction, ["Control", "F3"]);
// Remove the binding
game.keyMap.setKeyBinding(KeyBindingType.skipAction, null);type: KeyBindingType | string– The action typevalue: KeyBindingValue– A key, list of keys, ornullto remove the binding
getKeyBinding
Get the current binding of an action.
const current = game.keyMap.getKeyBinding(KeyBindingType.skipAction);addKeyBinding
Append one or more keys to an existing binding.
game.keyMap.addKeyBinding(KeyBindingType.skipAction, "F3");
// Append a list of keys
game.keyMap.addKeyBinding(KeyBindingType.skipAction, ["Alt", "Shift"]);getKeyBindings
Get all bindings.
onKeyBindingChange
Subscribe to binding changes.
const token = game.keyMap.onKeyBindingChange(KeyBindingType.skipAction, (value) => {
console.log("Binding changed", value);
});
token.cancel(); // stop listeningmatch
Determine if a key matches the predefined binding (case-insensitive).
if (game.keyMap.match(KeyBindingType.skipAction, event.key)) {
// do something
}Related Hooks
See useKeyBinding for a convenient React hook that automatically updates your UI when a binding changes.