GithubHelp home page GithubHelp logo

keyvent.js's Introduction

Keyvent.js

Keyboard events simulator.

Examples

Simulate 'keydown' events on the 'document' element:

keyvent.down(13); // You can use key codes...
keyvent.down('enter'); // ... a few alias...
keyvent.down('shift a'); // ... combination of keys...
keyvent.down('⇧ a'); // ... and some sugar!

The same is valid for simulating 'keyup' events:

keyvent.up(13);
keyvent.up('enter');
keyvent.up('shift a');
keyvent.up('⇧ a');

If you want to simulate keyboard events on other DOM elements, you have to set a new context (please note that the 'on' function takes a raw DOM element as parameter):

var headerDiv = document.getElementById('headerDiv');
keyvent.on(headerDiv).down('control');

You may want to keep a copy of this context to use later:

var headerDivKeyboard = keyvent.on(headerDiv);
(...)
headerDivKeyboard.up('space');

The following aliases are supported (borrowed from https://github.com/madrobby/keymaster): , shift, option, , alt, ctrl, control, command, , backspace, tab, clear, enter, return, esc, escape, space, up, down, left, right, home, end, pageup, pagedown, del, delete, and f1 through f19.

Notes

  • The initial intent of this lib is to support testing, but you can find a better usage for it. :-)
  • If you are using AMD (e.g. require.js) this lib becomes a module. Otherwise it'll create a global keyvent.

Browser Compatibility

I've ran the tests in Chrome and Firefox. If you find any incompatibility or want to support other browsers, please do a pull request with the fix! :-)

License

This is licensed under the feel-free-to-do-whatever-you-want-to-do license.

keyvent.js's People

Contributors

gtramontina avatar

Watchers

 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.