An open API service indexing awesome lists of open source software.

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

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