Giter Site home page Giter Site logo

keystroke.js's Introduction

keystroke.js

Assigning callbacks to key strokes

This library uses expressions to represent combinations of key presses and releases.

Demo

keystroke.js demo

Defining keystrokes

Keystrokes are represented in this form:

"<prefix><key>(<space><prefix><key>)*"

Prefix is a single character:

+: key is being pressed
-: key goes up
!: key is not being pressed

Key is the name of the key:

{a, b, c, d, ..., X, Z, backspace, tab, enter, shift, ctrl, alt, caps, esc, space, left, up, right, down, del}

Keystrokes Examples:

"+a": trigger when a is being pressed
"+a -b": trigger when a is being pressed and b is released
"+a +s -space": trigger when both a and s are being pressed and space is released
"+a !a": is never triggered
"+f !a": trigger when f is pressed, except if a is also being pressed
"-up +down": trigger when the up arrow key is released and the arrow down key is being pressed

The callbacks are called at fixed intervals, if the condition is met.

Requirements

Add underscore.js, jquery.js and keystroke.js to your html header.

Usage

var ks = new KeyStroker();

//add strokes
ks.add("+a +s", function(){
    console.log("You are pressing a and s.");
});

ks.add("+a -s", function(){
    console.log("You are pressing a and just released s.");
});

//run, checking for keystrokes at each 50ms
ks.run(50);

keystroke.js's People

Contributors

nrox avatar

Watchers

James Cloos 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.