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

keyboard-mapper

v1.2.4

Published

Map keyboard events

Downloads

4

Readme

keyboard-mapper

Map keyboard events. Work in progress and not really ready for others to use just yet!

I am using this for screen-based musical instruments (i.e. to trigger notes and change presets on synthesisers) and in particular hope to update with better considerations for screen reader systems in the near future.

CM 2022

structure

The "map" is a dictionary with two main categories: keymap and keyranges

keymap*: individual keys e.g. Space, Tab, and what I call keyranges (Key, Digit, Shift, Arrow, etc.)

keyranges: (should be renamed) -- the individual keys within the ranges/categories e.g. Digit(0-1), Key(a-z), Shift(Left,Right), Arrow(Left,Right,Up,Down), etc.

usage

build

At present the library sits in a single file: index.js.

The build task in package.json updates the docs and runs webpack to compile the test version.

At the time of writing, this is one of my first experimental modules and I'm still working out the conventions for building a module intended for the web. At the moment my method of compiling via webpack is a quick fix and a bit idiosyncratic. If you think the code might be useful and can help out with this, please get in touch!

code examples

More information in the docs folder...


Create an instance (will listen to the document by default)

const keyboardMapper = new KeyboardMapper();

Remove the listener (does not remove the instance altogether, for now):

keyboardMapper.unlisten();

Pass a default keyboard event as e from eventlistener...

Item is the value if the key sits in a keyrange (e.g. for the event with code 'KeyE', item will be 'E').

Direction is a boolean (true = keydown, false = keyup).

n.b. for keys that don't fall into a range, the arguments should be e, direction (todo: swap order of item and direction)

keyboardMapper.default = function(e, item, direction){

}

Right now this is probably more complicated to implement than it should be. I hope it'll be easier to manage overall than setting up event listeners ad hoc..

Initialise all keys with default method (not very useful):

keyboardMapper.keymap_init();

Set a general keyboard event (e.g. respond to Keys, Digit)

keyboardMapper.keymap['Key'] = function(e, item, direction){
    if(!e.repeat) console.log(item, direction)
}

Override a specific key

keyboardMapper.keyranges.Key.A = function(e, item, direction){console.log(e.keyCode, direction)}

Remove the override by setting to something not of type 'function':

keyboardMapper.keyranges.Key.A = undefined;

Preferred usage: set a default for the keys in general, and override individual keys with Object.assign...

Object.assign(keyboardMapper.keyranges,{
    Key:{
        A: (e, item, direction)=>{console.log('A', direction)},
        S: (e, item, direction)=>{console.log('S', direction ? 'up' : 'down')}
    }
})

Set individual key where category/range does not apply:

keyboardMapper.keymap['Tab']=function(e, down){
    console.log(down?'tab down':'tab up')
}