ClientKeybindings

ClientKeybindings

A class responsible for managing defined game keybinding. Each keybinding is a string key/value pair belonging to a certain namespace and a certain store scope.

When Foundry Virtual Tabletop is initialized, a singleton instance of this class is constructed within the global Game object as as game.keybindings.

Constructor

new ClientKeybindings()

See:

Members

actions :Map.<string, KeybindingActionConfig>

Registered Keybinding actions

Type:

activeKeys :Map.<string, Array.<KeybindingAction>>

A mapping of a string key to possible Actions that might execute off it

Type:

bindings :Map.<string, Array.<KeybindingActionBinding>>

A stored cache of Keybind Actions Ids to Bindings

Type:

moveKeys

An alias of the movement key set tracked by the keyboard

Methods

(package, static) _compareActions(a, b) → {number}

Compares two Keybinding Actions based on their Order

Parameters:
Name Type Description
a KeybindingAction

The first Keybinding Action

b KeybindingAction

the second Keybinding Action

Returns:
Type
number

_handleCanvasPan()

Handle panning the canvas using CTRL + directional keys

_registerCoreKeybindings()

Register core keybindings

get(namespace, action) → {Array.<KeybindingActionBinding>}

Get the current Bindings of a given namespace's Keybinding Action

Example

Retrieve the current Keybinding Action Bindings

game.keybindings.get("myModule", "showNotification");
Parameters:
Name Type Description
namespace string

The namespace under which the setting is registered

action string

The keybind action to retrieve

Returns:
Type
Array.<KeybindingActionBinding>

initialize()

Initializes the keybinding values for all registered actions

register(namespace, action, data)

Register a new keybinding

Example

Define a keybinding which shows a notification

game.keybindings.register("myModule", "showNotification", {
  name: "My Settings Keybinding",
  hint: "A description of what will occur when the Keybinding is executed.",
  uneditable: [
    {
      key: "Digit1",
      modifiers: ["Control"]
    }
  ],
  editable: [
    {
      key: "F1"
    }
  ],
  onDown: () => { ui.notifications.info("Pressed!") },
  onUp: () => {},
  restricted: true,                         // Restrict this Keybinding to gamemaster only?
  reservedModifiers: ["Alt""],              // If the ALT modifier is pressed, the notification is permanent instead of temporary
  precedence: CONST.KEYBINDING_PRECEDENCE.NORMAL
}
Parameters:
Name Type Description
namespace string

The namespace the Keybinding Action belongs to

action string

A unique machine-readable id for the Keybinding Action

data KeybindingActionConfig

Configuration for keybinding data

(async) resetDefaults()

Reset all client keybindings back to their default configuration.

(async) set(namespace, action, bindings)

Set the editable Bindings of a Keybinding Action for a certain namespace and Action

Example

Update the current value of a keybinding

game.keybindings.set("myModule", "showNotification", [
    {
      key: "F2",
      modifiers: [ "CONTROL" ]
    }
]);
Parameters:
Name Type Description
namespace string

The namespace under which the Keybinding is registered

action string

The Keybinding action to set

bindings Array.<KeybindingActionBinding>

The Bindings to assign to the Keybinding