Giter Site home page Giter Site logo

nintendo.js's Introduction

Nintendo.js

A key combo event handler for js. http://juancamiloestela.github.io/nintendo.js/

Installation

Just include the nintendo.js file in your html.

Usage

Nintendo.js works by detecting key combos. These can be used to trigger hidden functionalities or control elements in your site with keyboard commands.

Press the letter 'd'.

Nintendo.combo('d', function(){
	console.log('Combo: d');
});

To use capitals the SHIFT key is assumed.

Nintendo.combo('SHIFT + D', function(){
	console.log('Combo: SHIFT + D');
});

Combos can be simultaneous, press the alt key and 'd' at the same time.

Nintendo.combo('ALT + d', function(){
	console.log('Combo: ALT + d');
});

Combos can be sequential, press 'a', then 'b', then 'c'.

Nintendo.combo('a, b, c', function(){
	console.log('Combo: a, b, c');
});

Combos can also mix sequential and simultaneous commands, press 'a', then ALT + 'r'.

Nintendo.combo('a, ALT + r', function(){
	console.log('Combo: a, ALT + r');
});

You can use letters, numbers and special keys like ALT, CTRL, META, RETURN, TAB, SHIFT, LEFTARROW, UPARROW, RIGHTARROW, DOWNARROW. Press 'e', then '5', then the up arrow.

Nintendo.combo('e, 5, UPARROW', function(){
	console.log('Combo: e, 5, UPARROW');
});

How about a classic nintendo combo! a, b, a, a, UPARROW, DOWNARROW, a.

Nintendo.combo('a, b, a, a, UPARROW, DOWNARROW, a', function(){
	console.log('1 up!');
});

You can also control the event flow. Click on the text area an type 1,2,3. We are preventing the default behavior on the last key so when the combo is triggered, the number 3 will not appear on the textarea.

Nintendo.combo('1,2,3', function(e){
	e.preventDefault();
	console.log('Combo: 1, 2, 3');
});

Use it to make custom keyboard shortcuts for your apps, in this case CTRL + s wont trigger the browsers save dialog and call your custom functionality.

// on PC
Nintendo.combo('CTRL + s', function(e){
	e.preventDefault();
	console.log("Combo: override browser's save key shortcut.");
});

// on Mac
Nintendo.combo('META + s', function(e){
	e.preventDefault();
	console.log("Combo: override browser's save key shortcut.");
});

Roadmap

  • cross browser tests
  • Progressive callbacks on sequential combos

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.