New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

kaybee

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kaybee

A busy little keyboard input library for games.

latest
Source
npmnpm
Version
1.0.3
Version published
Weekly downloads
10
Maintainers
1
Weekly downloads
 
Created
Source

Kaybee 🐝

A very tiny keyboard input library for games.

  • Built on the KeyboardEvent API.
  • Zero dependencies.
  • < 0.4kb compressed.

Getting Started

via package manager:

yarn add kaybee or npm i -S kaybee

import { start } from "kaybee";

via CDN:

// Use your preferred CDN; here we use jspm.
import { start } from "https://jspm.dev/kaybee/dist/kaybee.js";

Usage

// Start listening for KeyboardEvents and tracking key state.
const kb = start({
  // These are the available options and their default values.
  target: window, // The EventTarget to listen for KeyboardEvents on.
  renameKeys: true, // Whether to normalize key names.
  enableRepeat: false, // Whether to call onKeyDown on "repeat" key events.
  onKeyDown: ({ key, code, repeat }) => {}, // Called when a key is pressed.
  onKeyUp: ({ key, code }) => {}, // Called when a key is released.
});
// Query key state by key name.
if (kb.getKey("f")) {
  // Do something.
}

// Query key state by key code.
if (kb.getCode("KeyW")) {
  // Do something else.
}
// Clean up the DOM event listeners when your game is finished.
kb.stop();

If renameKeys is true, then key names are transformed to more useful values using three simple rules:

  • All key names become lowercase. "A" -> "a"
  • Arrow keys are unprefixed. "ArrowLeft" -> "left"
  • And the space key is given a real value. " " -> "space"

Only the key name is changed by this option. The code name is unaffected.

This is recommended because the names given by the browser can be less than ideal for games. For example, "a" and "A" are given as two different key names.

See MDN's key and code pages for more info on names in the KeyboardEvent API.

FAQs

Package last updated on 21 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts