Giter VIP home page Giter VIP logo

keez's Introduction

keez

Frictionless hotkey handling for browsers

npm npm bundle size

Usage

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 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 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 / 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 (e.g. Escape or Backspace), the key property is used under the hood.

keez's People

Contributors

kripod avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.