npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@brianpeiris/kibo

v1.2.0

Published

Kibo is a simple JavaScript library for handling keyboard events.

Downloads

9

Readme

Kibo

Kibo is a simple JavaScript library for handling keyboard events.

Getting started

Kibo has no dependencies. Just include it in your HTML code:

<script type="text/javascript" src="kibo.js"></script>

Then set up an event listener by creating an instance of Kibo:

var k = new Kibo();

Kibo's constructor takes an optional argument - the HTML element on which you want to define the event handler. It should be an input, textarea or select element and defaults to window.document.

Syntax and usage

Two shorthand methods are provided - down and up, which take two arguments: one or more key combinations or wildcards, and a function to invoke when a matching event is fired on the element. The shorthand methods can be chained.

A key combination is a string consisting of zero or more modifiers and a key name or, alternatively, one or more modifiers. You can pass the short-hand methods a single key combination or an array of one or more key combinations.

When the function is invoked, it is passed the event as its sole argument. Feel free to ignore it if you don't need to do anything else about it. If the function returns false, the default action will be prevented.

A lastKey method is provided for querying Kibo about which key was involved in the last keyboard event. It will return the key's name or undefined if the last key is not supported. Additionally, you can ask lastKey about a particular modifier key and it will reply either true or false.

Supported keys

Kibo understands these keys and is case-insensitive about their spelling:

  • modifiers shift, ctrl, alt

  • letters a to z

  • numbers 0 to 9

  • functions f1 to f12

  • arrows left, up, right, down

  • enter, esc, space, backspace, delete, insert, tab, page_up, page_down, home, end, caps_lock, num_lock

  • wildcards any, any arrow, any number, any letter, any f

Examples

var k = new Kibo();

Single or multiple key combinations

k.down(['up', 'down'], function() {
  console.log('up or down arrow key pressed');
}).up('tab', function() {
  console.log('TAB key released');
});

Key combinations with modifiers

function handler() {
  console.log('last key: ' + k.lastKey());
}

k.down(['shift q', 'ctrl alt x'], handler);

Wildcards

k.down(['any letter', 'any number'], function() {
  console.log('letter or number key pressed');
  console.log('shift key was' + (k.lastKey('shift') ? '' : ' not') + ' pressed');
});

k.up('any', function() {
  console.log('key released');
});

Preventing the default action

k.down('f5', function() { return false; });

License

Kibo is released under the MIT License. Copyright (c) 2013 marquete.