https://github.com/mary-ext/pkg-keybinds
Lightweight and "sensible" keyboard handler
https://github.com/mary-ext/pkg-keybinds
typescript web
Last synced: 11 months ago
JSON representation
Lightweight and "sensible" keyboard handler
- Host: GitHub
- URL: https://github.com/mary-ext/pkg-keybinds
- Owner: mary-ext
- License: bsd-3-clause
- Created: 2024-09-24T03:02:15.000Z (over 1 year ago)
- Default Branch: trunk
- Last Pushed: 2024-09-24T19:22:14.000Z (over 1 year ago)
- Last Synced: 2025-03-19T21:28:35.436Z (over 1 year ago)
- Topics: typescript, web
- Language: TypeScript
- Homepage:
- Size: 10.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @externdefs/keybinds
Library for handling keyboard shortcuts (keybinds).
- **Sensible**, tries to achieve a default that makes "sense"
Keybinds can't interfere with common user expectations
- **Lightweight**, much smaller than `hotkeys-js` library.
Use this [web page](https://mary.my.id/tools/keydown-visualizer) to get the
right keybinds for use here.
```ts
const handler = createKeybindHandler({
'$mod+K'() {
// Open search modal...
},
s() {
// Save...
},
});
window.addEventListener('keydown', handler);
```
## "Sensible" keyboard handling
The library reserves certain keybinds for the following scenarios:
- ``, `` and `
`
- Text insertion (`a`, `s`, ...)
- Uppercase text insertion (`Shift+A`, `Shift+S`, ...)
- Text deletion (`Backspace`, `$mod+Backspace`)
- Cursor per-char positioning (`ArrowLeft`, `ArrowRight`, ...)
- Cursor per-char selection (`Shift+ArrowLeft`, `Shift+ArrowRight`, ...)
- Cursor per-word positioning (`$mod+ArrowLeft`, `$mod+ArrowRight`, ...)
- Cursor per-word selection (`$mod+Shift+ArrowLeft`, `$mod+Shift+ArrowRight`, ...)
- Common text manipulation shortcuts (`$mod+a`, `$mod+v`, ...)
- Multiline only: New line insertion (`Enter`)
- Date/time inputs only: Open picker UI (`Enter`)
- ``
- Tick/unticking check (`Space`)
- `` and ``
- Selection (`ArrowLeft`, `ArrowRight`)
- `` and ``
- Action trigger (`Space`, `Enter`)
- ``
- Link navigation (`Enter`, `$mod+Enter`, ...)
- ``
- Jump to value (`a`, `s`, ...)
`createKeybindHandler` will also call `.preventDefault()` on matching events by
default, you can disable this by passing `false` as the second parameter. It's
recommended to just write your own handler however if you need flexibility, all
the relevant functions are exported.
## License
BSD-3-Clause © Mary