Coder Social home page Coder Social logo

keymaster's Introduction

keymaster.js

keymaster.js is a simple (~60 LoC) micro-library for defining and dispatching keyboard shortcuts. It has no dependencies.

It’s a work in progress, so spare me your nerdrage and instead contribute! Patches are welcome, but they are not guaranteed to make it in.

Two global methods are exposed, key for defining shortcuts, and keyScope for switching scope.

See test.html for a live demo.

key('c', 'issues', function(){
 console.log('c/issues');
});

key('command+r, ctrl+r', 'issues', function(){
  console.log('Hijacked Command+R or Ctrl+R, damn!');
  return false;
});

key('i', function(){
  keyScope('issues');
  console.log('Switched to "issues" scope. Command+R or Ctrl+R is now no longer reloading...');
});

key('i', function(){
  console.log('(example of multiple assignment)');
});

key('o, enter, left', function(){
  console.log('o, enter or left pressed!');
});

key('ctrl+c', function(){
  console.log('this is not the command line');
});

key('⌘+right,shift+left,ctrl+shift+alt+d', function(event){
  console.log('command+right, or shift+left, or ctrl+shift+alt+d');
  console.log('here is the event: ', event);
  return false; // prevent default && stop propagation
});

TODO

  • Make behavior with INPUT / SELECT / TEXTAREA configurable
  • Comprehensive test suite
  • Make it work on IE (7+) (low priority)

keymaster.js is (c) 2011 Thomas Fuchs and may be freely distributed under the MIT license. See the MIT-LICENSE file.

keymaster's People

Contributors

madrobby avatar devongovett avatar livibetter avatar rafbm avatar

Stargazers

Dmitry Demeshchuk avatar

Watchers

Dmitry Demeshchuk avatar James Cloos 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.