# keez

> Frictionless hotkey handling for browsers

Latest version **1.0.1** (published 2020-12-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install keez
pnpm add keez
yarn add keez
bun add keez
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2020-12-12 |
| First published | 2020-12-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 16 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 55 |
| Author | Kristóf Poduszló |
| Maintainers | kripod |
| Keywords | hotkey, shortcut, keyboard, event, handler |

## Links

- npm: https://www.npmjs.com/package/keez
- Repository: https://github.com/kripod/keez
- Homepage: https://github.com/kripod/keez#readme
- Issues: https://github.com/kripod/keez/issues
- npm.io page: https://npm.io/package/keez

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2020-12-12
- 1.0.0 — 2020-12-12

## README

# keez

Frictionless hotkey handling for browsers

[![npm](https://img.shields.io/npm/v/keez)](https://www.npmjs.com/package/keez)
[![npm bundle size](https://img.shields.io/bundlephobia/minzip/keez)](https://bundlephobia.com/result?p=keez)

## Usage

```js
import { captureKeys } from "keez";

const saveCommand = captureKeys("CmdOrCtrl", "S");
const italicCommand = captureKeys("CmdOrCtrl", "I");

document.addEventListener("keydown", (event) => {
  if (saveCommand(event)) {
    /* Do something, e.g. call `fetch` */
  } else if (italicCommand(event)) {
    /* Do something else, e.g. format selected text */
  }
});
```

## Features

- `CmdOrCtrl` modifier for interoperability between operating systems
- Supports synthetic events (e.g. for [React](https://reactjs.org/) elements)
- Calls `event.preventDefault()` when a match is found, suppressing handlers of the underlying browser (or even the system)
- TypeScript-based code completion for common modifier keys
- Low overhead, compared to similar libraries

## Browser support

[Every browser with the `Set` built-in](https://caniuse.com/mdn-javascript_builtins_set) is supported out of the box.

## Implementation details

There are quite a few attributes to handle keystrokes with:

|                                          | Layout-aware | Modifier-independent | Supports all events | Named non-printables |
| ---------------------------------------- | :----------: | :------------------: | :-----------------: | :------------------: |
| `key`                                    |      ✓       |          ✗           |          ✓          |        **✓**         |
| `code`                                   |      ✗       |          ✓           |          ✓          |          ✓           |
| `keyCode`&nbsp;/&nbsp;`which` _(legacy)_ |    **✓**     |        **✓**         |        **✓**        |          ✗           |
| `charCode` _(legacy)_                    |      ✓       |          ✓           |          ✗          |          ✗           |

Despite being a legacy attribute, `keyCode` is used in comparisons by default. It’s independent from modifiers, unlike the modern `key` alternative.

However, when it comes to [named key attribute values](https://www.w3.org/TR/uievents-key/#named-key-attribute-values) (e.g. `Escape` or `Backspace`), the `key` property is used under the hood.

---
_Source: https://npm.io/package/keez · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
