Keyboard or mouse event.
Keyboard or mouse event from an event listener.
Single chord or array of chords that represent a combination of Token
elements that meet the conditions in the specified event.
Callback to fire if a chord match is found.
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.
Keyboard or mouse event.
Keyboard or mouse event from an event listener.
Builder that adds handlers that map to key combinations and mouse buttons.
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.
})
});
}
Fires the specified
listenerif the specified combination ofchordswere pressed/clicked from the specifiedevent.