Skip to content
Newer
Older
100644 72 lines (51 sloc) 2.61 KB
dcfeb8b @ccampbell Initial commit
authored Jul 1, 2012
1 # Mousetrap
1494d10 @ccampbell Update master
authored Jul 5, 2012
2
7a93b53 @ccampbell Increase size again :(
authored Jul 10, 2012
3 Mousetrap is a simple library for handling keyboard shortcuts in Javascript.
1494d10 @ccampbell Update master
authored Jul 5, 2012
4
a10ab3a @ccampbell Update size
authored Aug 10, 2012
5 It is around **1.7kb** minified and gzipped and **3kb** minified, has no external dependencies, and has been tested in the following browsers:
1494d10 @ccampbell Update master
authored Jul 5, 2012
6
7 - Internet Explorer 6+
8 - Safari
9 - Firefox
10 - Chrome
11
91d4eb3 @ccampbell Explain what makes Mousetrap different than similar libraries. Fixes #28
authored Jul 9, 2012
12 It has support for ``keypress``, ``keydown``, and ``keyup`` events on specific keys, keyboard combinations, or key sequences.
ed6f4a7 @ccampbell Update master
authored Jul 5, 2012
13
3465b65 @ccampbell Add Gittip link
authored Jul 29, 2012
14 If you would like to donate to help support Mousetrap development use [Gittip](https://www.gittip.com/ccampbell).
15
bcf2713 @ccampbell Update master
authored Jul 5, 2012
16 ## Getting started
1494d10 @ccampbell Update master
authored Jul 5, 2012
17
f236b95 @ccampbell Fix typo
authored Jul 11, 2012
18 1. Include mousetrap on your page before the closing ``</body>`` tag
1494d10 @ccampbell Update master
authored Jul 5, 2012
19
20 ```html
21 <script src="/path/to/mousetrap.min.js"></script>
22 ```
23
bcf2713 @ccampbell Update master
authored Jul 5, 2012
24 2. Add some keyboard events to listen for
1494d10 @ccampbell Update master
authored Jul 5, 2012
25
26 ```html
27 <script>
28 // single keys
29 Mousetrap.bind('4', function() { console.log('4'); });
b147dd1 @ccampbell Update README
authored Jul 15, 2012
30 Mousetrap.bind("?", function() { console.log('show shortcuts!'); });
1494d10 @ccampbell Update master
authored Jul 5, 2012
31 Mousetrap.bind('esc', function() { console.log('escape'); }, 'keyup');
32
33 // combinations
34 Mousetrap.bind('command+shift+K', function() { console.log('command shift k'); });
c9e6659 @ccampbell Update README
authored Jul 15, 2012
35
36 // map multiple combinations to the same callback
b147dd1 @ccampbell Update README
authored Jul 16, 2012
37 Mousetrap.bind(['command+k', 'ctrl+k'], function() {
38 console.log('command k or control k');
39
40 // return false to prevent default browser behavior
41 // and stop event from bubbling
42 return false;
43 });
1494d10 @ccampbell Update master
authored Jul 5, 2012
44
45 // gmail style sequences
46 Mousetrap.bind('g i', function() { console.log('go to inbox'); });
47 Mousetrap.bind('* a', function() { console.log('select all'); });
48
49 // konami code!
50 Mousetrap.bind('up up down down left right left right b a enter', function() {
51 console.log('konami code');
52 });
53 </script>
54 ```
55
91d4eb3 @ccampbell Explain what makes Mousetrap different than similar libraries. Fixes #28
authored Jul 9, 2012
56 ## Why Mousetrap?
57
58 There are a number of other similar libraries out there so what makes this one different?
59
60 - There are no external dependencies, no framework is required
61 - You are not limited to ``keydown`` events (You can specify ``keypress``, ``keydown``, or ``keyup`` or let Mousetrap choose for you).
b147dd1 @ccampbell Update README
authored Jul 16, 2012
62 - You can bind key events directly to special keys such as ``?`` or ``*`` without having to specify ``shift+/`` or ``shift+8`` which are not consistent across all keyboards
63 - It works with international keyboard layouts
91d4eb3 @ccampbell Explain what makes Mousetrap different than similar libraries. Fixes #28
authored Jul 9, 2012
64 - You can bind Gmail like key sequences in addition to regular keys and key combinations
65 - You can programatically trigger key events with the ``trigger()`` method
66 - It works with the numeric keypad on your keyboard
67 - The code is well documented/commented
68
1494d10 @ccampbell Update master
authored Jul 5, 2012
69 ## Documentation
70
7a93b53 @ccampbell Increase size again :(
authored Jul 11, 2012
71 Full documentation can be found at http://craig.is/killing/mice
Something went wrong with that request. Please try again.