Options
All
  • Public
  • Public/Protected
  • All
Menu

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.

see

{@link Game#keybindings}

see

{@link SettingKeybindingConfig}

see

KeybindingsConfig

Hierarchy

  • ClientKeybindings

Index

Constructors

Properties

actions: Map<string, KeybindingActionConfig>

Registered Keybinding actions

activeKeys: Map<string, KeybindingAction[]>

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

bindings: Map<string, KeybindingActionBinding[]>

A stored cache of Keybind Actions Ids to Bindings

MOVEMENT_DIRECTIONS: { UP: string; LEFT: string; DOWN: string; RIGHT: string } = ...

Type declaration

  • UP: string
  • LEFT: string
  • DOWN: string
  • RIGHT: string
ZOOM_DIRECTIONS: { IN: string; OUT: string } = ...

Type declaration

  • IN: string
  • OUT: string

Accessors

  • get moveKeys(): Set<string>
  • An alias of the movement key set tracked by the keyboard

    Returns Set<string>

Methods

  • initialize(): void
  • Initializes the keybinding values for all registered actions

    Returns void

  • register(namespace: string, action: string, data: KeybindingActionConfig): void
  • 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""], // On ALT, the notification is permanent instead of temporary
    precedence: CONST.KEYBINDING_PRECEDENCE.NORMAL
    }

    Parameters

    • 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

    Returns void

  • get(namespace: string, action: string): 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

    • namespace: string

      The namespace under which the setting is registered

    • action: string

      The keybind action to retrieve

    Returns KeybindingActionBinding[]

  • set(namespace: string, action: string, bindings: KeybindingActionBinding[]): Promise<any>
  • 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

    • namespace: string

      The namespace under which the Keybinding is registered

    • action: string

      The Keybinding action to set

    • bindings: KeybindingActionBinding[]

      The Bindings to assign to the Keybinding

    Returns Promise<any>

  • resetDefaults(): Promise<any>
  • Reset all client keybindings back to their default configuration.

    Returns Promise<any>

  • _registerCoreKeybindings(): void
  • Register core keybindings

    Returns void

  • _handleCanvasPan(): any
  • Handle panning the canvas using CTRL + directional keys

    Returns any

  • Handle keyboard movement once a small delay has elapsed to allow for multiple simultaneous key-presses.

    Parameters

    • context: KeyboardEventContext

      The context data of the event

    • layer: InteractionLayer

      The active InteractionLayer instance

    Returns void

  • _onPan(context: KeyboardEventContext, movementDirections: string[]): boolean
  • Handle Pan action

    Parameters

    • context: KeyboardEventContext

      The context data of the event

    • movementDirections: string[]

      The Directions being panned in

    Returns boolean

  • _compareActions(a: KeybindingAction, b: KeybindingAction): number
  • Compares two Keybinding Actions based on their Order

    internal

    Parameters

    • a: KeybindingAction

      The first Keybinding Action

    • b: KeybindingAction

      the second Keybinding Action

    Returns number

  • _validateBindings(values: KeybindingActionBinding[]): KeybindingActionBinding[]
  • A helper method that, when given a value, ensures that the returned value is a standardized Binding array

    Parameters

    • values: KeybindingActionBinding[]

      An array of keybinding assignments to be validated

    Returns KeybindingActionBinding[]

    An array of keybinding assignments confirmed as valid

  • _validateModifiers(keys: string[]): string[]
  • Validate that assigned modifiers are allowed

    Parameters

    • keys: string[]

      An array of modifiers which may be valid

    Returns string[]

    An array of modifiers which are confirmed as valid

  • _onSelectAllObjects(event: KeyboardEvent, context: KeyboardEventContext): boolean
  • Handle Select all action

    Parameters

    • event: KeyboardEvent

      The originating keyboard event

    • context: KeyboardEventContext

      The context data of the event

    Returns boolean

  • _onCycleView(context: KeyboardEventContext): boolean
  • Handle Cycle View actions

    Parameters

    • context: KeyboardEventContext

      The context data of the event

    Returns boolean

  • _onDismiss(context: KeyboardEventContext): boolean
  • Handle Dismiss actions

    Parameters

    • context: KeyboardEventContext

      The context data of the event

    Returns boolean

  • _onToggleCharacterSheet(event: KeyboardEvent, context: KeyboardEventContext): ActorSheet
  • Open Character sheet for current token or controlled actor

    Parameters

    • event: KeyboardEvent

      The initiating keyboard event

    • context: KeyboardEventContext

      The context data of the event

    Returns ActorSheet

  • _onTarget(context: KeyboardEventContext): boolean
  • Handle action to target the currently hovered token.

    Parameters

    • context: KeyboardEventContext

      The context data of the event

    Returns boolean

  • _onDelete(event: KeyboardEvent, context: KeyboardEventContext): boolean
  • Handle DELETE Keypress Events

    Parameters

    • event: KeyboardEvent

      The originating keyboard event

    • context: KeyboardEventContext

      The context data of the event

    Returns boolean

  • _onMeasuredRulerMovement(context: KeyboardEventContext): boolean
  • Handle Measured Ruler Movement Action

    Parameters

    • context: KeyboardEventContext

      The context data of the event

    Returns boolean

  • _onPause(context: KeyboardEventContext): boolean
  • Handle Pause Action

    Parameters

    • context: KeyboardEventContext

      The context data of the event

    Returns boolean

  • _onHighlight(context: KeyboardEventContext): boolean
  • Handle Highlight action

    Parameters

    • context: KeyboardEventContext

      The context data of the event

    Returns boolean

  • _onMacroExecute(context: KeyboardEventContext, number: number): boolean
  • Handle Macro executions

    Parameters

    • context: KeyboardEventContext

      The context data of the event

    • number: number

      The numbered macro slot to execute

    Returns boolean

  • _onMacroPageSwap(context: KeyboardEventContext, page: number): boolean
  • Handle Macro page swaps

    Parameters

    • context: KeyboardEventContext

      The context data of the event

    • page: number

      The numbered macro page to activate

    Returns boolean

  • _onCopy(context: KeyboardEventContext): boolean
  • Handle action to copy data to clipboard

    Parameters

    • context: KeyboardEventContext

      The context data of the event

    Returns boolean

  • _onPaste(context: KeyboardEventContext): boolean
  • Handle Paste action

    Parameters

    • context: KeyboardEventContext

      The context data of the event

    Returns boolean

  • _onUndo(context: KeyboardEventContext): boolean
  • Handle Undo action

    Parameters

    • context: KeyboardEventContext

      The context data of the event

    Returns boolean

  • _onZoom(context: KeyboardEventContext, zoomDirection: { IN: string; OUT: string }): boolean
  • Handle presses to keyboard zoom keys

    Parameters

    • context: KeyboardEventContext

      The context data of the event

    • zoomDirection: { IN: string; OUT: string }

      The direction to zoom

      • IN: string
      • OUT: string

    Returns boolean

  • _onFocusChat(context: KeyboardEventContext): boolean
  • Bring the chat window into view and focus the input

    Parameters

    • context: KeyboardEventContext

      The context data of the event

    Returns boolean