Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

keycon

daybrush635.8kMIT1.4.0TypeScript support: included

Keyboard Controller

key, keycode, keyboard, component, esm

readme

keycon npm version

Keyboard Controller

Installation

npm i keycon
<script src="https://daybrush.com/keycon/release/latest/dist/keycon.min.js"></script>

How to use

import KeyController, { getCombi, getKey } from "keycon";

const keycon = new KeyController();

// The focus went out of the browser.
keycon.on("blur", () => {
    console.log("blur");
});
// keydown all
keycon.keydown(e => {
    console.log(e);
});
// keydown space
keycon.keydown("space", e => {
    console.log(e);
});
// keydown alt + space combination
keycon.keydown(["alt", "space"], e => {
    // ["alt", "space"]
    console.log(getCombi(e));
    // "space"
    console.log(getKey(e.keyCode));

    console.log(e);
});

// keyup all
keycon.keyup(e => {
    console.log(e);
});
// keyup space
keycon.keydown("space", e => {
    console.log(e);
});
// keyup alt + space combination
keycon.keyup(["alt", "space"], e => {
    console.log(e);
});

changelog

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

1.3.2 (2022-10-19)

:rocket: New Features

:mega: Other

  • update packages versions (07f0b13)

1.3.0 (2022-09-24)

:rocket: New Features

:bug: Bug Fix

:mega: Other

  • update packages versions (94156a3)

1.2.2 (2022-07-23)

:bug: Bug Fix

1.2.1 (2022-07-23)

:mega: Other

  • fix package.json scripts (36742de)