This is a HARD fork from (tinykeys)[https://github.com/jamiebuilds/tinykeys] to be used in glifox as the default keymap handler. This fork is made because the current tinykeys repo is not currently active, and i plan to make some changes to it in order to be more consistent with other tools and fit the current project needs.
npm install @glifox/desmosThe package exposes 3 funtions:
attachKeybindings: Directly adds the keybindins to the pased element.createKeybindingsHandler: Returns a EventListener width the keybindins to be added.parseKeybinding: Returns a list with de internal representation of the shorcut.
attachKeybindings(window, {
"shift-d": () => {
alert("The 'Shift' and 'd' keys were pressed at the same time")
},
"y e e t": () => {
alert("The keys 'y', 'e', 'e', and 't' were pressed in order")
},
"$mod-([1-9])": event => {
event.preventDefault()
alert(`Either 'Control-${event.key}' or 'Meta-${event.key}' were pressed`)
},
})const handler = createKeybindingsHandler({
"shift-d": () => {
alert("The 'Shift' and 'd' keys were pressed at the same time")
},
"y e e t": () => {
alert("The keys 'y', 'e', 'e', and 't' were pressed in order")
},
"$mod-([1-9])": event => {
event.preventDefault()
alert(`Either 'Control-${event.key}' or 'Meta-${event.key}' were pressed`)
},
})
// handler: (event: KeyboardEvent, ...args: any[]): voidimport { parseKeybinding } from "tinykeys"
let parsedShortcut = parseKeybinding("$mod-shift-k $mod-1")
// parsedShortcut = [
// [["Meta", "Shift"], "K"],
// [["Meta"], "1"],
// ]for more advanced users, you may whant to take a look a the original repositori where @jamiebuilds make a beautifull documentation about it's creation.
- Keybindings use
-instead of+to separete keystrokes - the handler returns a function that resives an arbitrary amount of arguments
- the modificators are more flexible, resiving "alt", "ctrl" and more as valid modifiers
- some function name has change.