Map actions to keys in KeyboardEvents.
npm install @efinitytech/forkey
forkey(km: KeyMap): (e: KeyboardEvent) => void The declaration for KeyMap looks like:
``ts`
type KeyMap = { [key: string]: boolean | FunctionAcceptsKeyboardEventReturnsBoolean };event.key
If a key matches or event.code, it will run the associated function. If the function returns true, it will call event.preventDefault(). Or, if a boolean value is provided instead of the function, true will call event.preventDefault().
html
`$3
`jsx
import forkey from 'forkey';
// in markup:
// Case-insensitive. Evaluating to true calls preventDefault on the event.
'enter': true,
// Custom handler.
ShiftLeft(e) => {
console.log('event:', e);
// Returning true will also call preventDefault on the event.
return true;
}
})} />
``