Skip to content

glifox/desmos

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Keymap from tinykeys

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.

Install

npm install @glifox/desmos

Usage

The 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

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`)
	},
})

createKeybindingsHandler

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[]): void

parseKeybinding

import { parseKeybinding } from "tinykeys"

let parsedShortcut = parseKeybinding("$mod-shift-k $mod-1")

// parsedShortcut = [
//   [["Meta", "Shift"], "K"],
//   [["Meta"], "1"],
// ]

¿Advanced?

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.

Key Difrences

  • 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.

About

This is a HARD fork from (tinykeys)[https://github.com/jamiebuilds/tinykeys].

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published