# @pirxpilot/k

> keyboard event dispatcher

Latest version **1.0.1** (published 2022-04-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install @pirxpilot/k
pnpm add @pirxpilot/k
yarn add @pirxpilot/k
bun add @pirxpilot/k
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2022-04-13 |
| First published | 2017-12-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 8.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Amir Abu Shareb |
| Maintainers | pirxpilot |
| Keywords | browser, keyboard |

## Links

- npm: https://www.npmjs.com/package/@pirxpilot/k
- Repository: https://github.com/pirxpilot/k
- Homepage: https://github.com/pirxpilot/k#readme
- Issues: https://github.com/pirxpilot/k/issues
- npm.io page: https://npm.io/package/@pirxpilot/k

## Dependencies (3)

- [component-os](https://npm.io/package/component-os.md) *
- [yields-keycode](https://npm.io/package/yields-keycode.md) *
- [yields-k-sequence](https://npm.io/package/yields-k-sequence.md) *

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2022-04-13
- 1.0.0 — 2017-12-11
- 0.7.2 — 2017-12-11

## README

# k

  keyboard event dispatcher.

## Installation

    $ component install yields/k

## Features

  - `super` keyword is `command` on mac and `ctrl` on anything else.
  - gmail like sequences `(a b c *)`
  - key combos
  - nice simple api
  - you can unbind anything you bind

## Example

```js
var k = require('k')(window);

// combos
k('command + shift + enter', fn);

// on OSX `super` will be replaced with `command`
// on other operating systems it will be replaced with `ctrl`.
k('super + k', fn);

// sequences
k('a b c', fn);
k('* b c', fn);
k('super + shift + a b c', fn);
```

## API

### k(el)

  Create a new keyboard dispatcher on the given `element`

### k(keys, fn)

  Bind the given `fn` on `keys`.

### .el

  the element `k` is listening on.

### #bind

  Bind `keys` with `fn(e)`.

### #unbind

  Unbind all listeners of `keys`,
  unbind `fn` with `keys`,
  unbind all listeners on all keys.

```js
k.unbind(); // => unbind all listeners
k.unbind('enter'); // => unbind all enter listeners
k.unbind('command + enter'); // => unbind all `command + enter` listeners
k.unbind('command + enter', fn); // => unbind `fn` just from `command + enter`
```

### #destroy

  Removes all listeners on `k.el`.
  Removes all `k.listeners`.

### #ignore

  this function is called just before any handlers are called,
  if it returns `true` no handlers will be called for this event.

  by default it returns `true` for `input`, `textarea` or `select`.

  if you still want `k` to handle `inputs` you can `k.ignore = false`.

### .shift

  `true` if `shiftKey` is down.

### .ctrl

  `true` if `ctrlKey` is down.

### .alt

  `true` if `alt` is down.

### .command

  `true` if `command` is down.

### .modifiers

  `null` if no modifiers are down, otherwise it's `true`.

### .super

  `true` if `command` or `ctrl` are down (osx / others)

## Tests

```bash
$ make test
```

## License

  MIT

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