keycon
TypeScript icon, indicating that this package has built-in type declarations

1.4.0 • Public • Published

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);
});

Package Sidebar

Install

npm i keycon

Weekly Downloads

55,735

Version

1.4.0

License

MIT

Unpacked Size

214 kB

Total Files

31

Last publish

Collaborators

  • younkue