Function handleChords

  • Fires the specified listener if the specified combination of chords were pressed/clicked from the specified event.

    Type Parameters

    Parameters

    • event: E

      Keyboard or mouse event from an event listener.

    • chords: ChordInput

      Single chord or array of chords that represent a combination of Token elements that meet the conditions in the specified event.

    • listener: ChordMatchListener<E>

      Callback to fire if a chord match is found.

    Returns void

    Single Chord Input

    function handleKeyDown(event: KeyboardEvent): void {
    handleChords(event, Modifier.Alt | Key.LetterC, () => {
    // Fired only when Alt + C is pressed.
    });
    }

    Multiple Chord Input

    function handleKeyDown(event: KeyboardEvent): void {
    handleChords(event, [Modifier.Alt | Key.LetterC, Key.LetterC], (event) => {
    // Fired when Alt + C or the letter C is pressed.

    // Event can be accessed from the listener if needed:
    event.preventDefault();
    });
    }
  • Fires the handlers that map to the specified builder describing the combinations of Token elements or conditions for the specified keyboard or mouse event.

    Type Parameters

    Parameters

    • event: E

      Keyboard or mouse event from an event listener.

    • builder: ChordHandlerBuilder<E>

      Builder that adds handlers that map to key combinations and mouse buttons.

    Returns void

    function handleKeyDown(event: KeyboardEvent): void {
    handleChords(event, (handler) => {
    handler
    .on(Modifier.Alt | Key.LetterC, () => {
    // Fired only when Alt + C is pressed.
    })
    .on(Key.LetterC, () => {
    // Fired only when C is pressed (without modifiers).
    })
    .on([Modifier.Alt | Key.LetterC, Key.LetterC], (event) => {
    // Fired when Alt + C _or_ C is pressed.

    // Event can be accessed from the listener if needed:
    event.preventDefault();
    })
    // Passing in a function that takes an Event as its first argument:
    .when(isPrintableCharPressed, () => {
    // A letter or number was pressed.
    })
    // Passing in a boolean:
    .when(isPrintableCharPressed(event), () => {
    // A letter or number was pressed.
    })
    });
    }