All Projects → ccampbell → Mousetrap

ccampbell / Mousetrap

Licence: apache-2.0
Simple library for handling keyboard shortcuts in Javascript

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to Mousetrap

Aquatouch
Dynamic Custom Macros for your MacBook TouchBar! (Supports 40+ Apps and Websites)
Stars: ✭ 125 (-98.86%)
Mutual labels:  keyboard-shortcuts, keyboard
Switch Desktop
⚡️ Keyboard-driven commands to navigate your apps faster
Stars: ✭ 320 (-97.07%)
Mutual labels:  keyboard-shortcuts, keyboard
react-hotkey-tooltip
A global Hotkey provider with built in tooltip for React
Stars: ✭ 34 (-99.69%)
Mutual labels:  keyboard-shortcuts, mousetrap
Chordly
Chordly is a javascript library that may be used to detect and act upon key sequences entered by a user.
Stars: ✭ 14 (-99.87%)
Mutual labels:  keyboard, keyboard-shortcuts
Repeat
Cross-platform mouse/keyboard record/replay and automation hotkeys/macros creation, and more advanced automation features.
Stars: ✭ 763 (-93.02%)
Mutual labels:  keyboard-shortcuts, keyboard
use-keyboard-shortcut
A custom hook that allows adding keyboard shortcuts to React applications
Stars: ✭ 41 (-99.63%)
Mutual labels:  keyboard, keyboard-shortcuts
input-remapper
🎮 An easy to use tool to change the mapping of your input device buttons.
Stars: ✭ 1,142 (-89.56%)
Mutual labels:  keyboard, keyboard-shortcuts
Keymapper
📱 An Android app that maps any keys to actions.
Stars: ✭ 207 (-98.11%)
Mutual labels:  keyboard-shortcuts, keyboard
Combokeys
Web browser keyboard shortcuts. CommonJS, NPM.
Stars: ✭ 675 (-93.83%)
Mutual labels:  keyboard-shortcuts, keyboard
Shortcutmapper
A visual keyboard shortcuts explorer for popular applications.
Stars: ✭ 657 (-93.99%)
Mutual labels:  keyboard-shortcuts, keyboard
MyAHKScript
An AutoHotkey script that I use on the daily basis for my PC. Comes with an installer that takes care of everything for you.
Stars: ✭ 22 (-99.8%)
Mutual labels:  keyboard, keyboard-shortcuts
Evscript
A tiny sandboxed Dyon scripting environment for evdev input devices that lets you do e.g. xcape in Wayland
Stars: ✭ 91 (-99.17%)
Mutual labels:  keyboard-shortcuts, keyboard
keys
⌨️ Keyboard Shortcuts for 'shiny'
Stars: ✭ 37 (-99.66%)
Mutual labels:  keyboard-shortcuts, mousetrap
react-keyevent
An easy-to-use keyboard event react component, Package size less than 3kb
Stars: ✭ 38 (-99.65%)
Mutual labels:  keyboard, keyboard-shortcuts
Powerkey
Remap your Macbook's power key to Forward Delete
Stars: ✭ 212 (-98.06%)
Mutual labels:  keyboard-shortcuts, keyboard
ember-key-manager
A service for (un)binding keyboard up and down events.
Stars: ✭ 39 (-99.64%)
Mutual labels:  keyboard, keyboard-shortcuts
Keyboardjs
A JavaScript library for binding keyboard combos without the pain of key codes and key combo conflicts.
Stars: ✭ 1,881 (-82.8%)
Mutual labels:  keyboard-shortcuts, keyboard
Chromium Vim
Vim bindings for Google Chrome.
Stars: ✭ 2,150 (-80.34%)
Mutual labels:  keyboard-shortcuts, keyboard
Hotkeys
➷ A robust Javascript library for capturing keyboard input. It has no dependencies.
Stars: ✭ 5,165 (-52.77%)
Mutual labels:  keyboard-shortcuts, keyboard
Quickcut
QuickCut is a cross-platform keyboard manager that both facilitates key mapping and allows the configuration of global hotkeys triggering user defined actions.
Stars: ✭ 84 (-99.23%)
Mutual labels:  keyboard-shortcuts, keyboard

Mousetrap

CDNJS

Mousetrap is a simple library for handling keyboard shortcuts in Javascript.

It is licensed under the Apache 2.0 license.

It is around 2kb minified and gzipped and 4.5kb minified, has no external dependencies, and has been tested in the following browsers:

  • Internet Explorer 6+
  • Safari
  • Firefox
  • Chrome

It has support for keypress, keydown, and keyup events on specific keys, keyboard combinations, or key sequences.

Getting started

  1. Include mousetrap on your page before the closing </body> tag

    <script src="/path/to/mousetrap.min.js"></script>

    or install mousetrap from npm and require it

    var Mousetrap = require('mousetrap');
  2. Add some keyboard events to listen for

    <script>
        // single keys
        Mousetrap.bind('4', function() { console.log('4'); });
        Mousetrap.bind("?", function() { console.log('show shortcuts!'); });
        Mousetrap.bind('esc', function() { console.log('escape'); }, 'keyup');
    
        // combinations
        Mousetrap.bind('command+shift+k', function() { console.log('command shift k'); });
    
        // map multiple combinations to the same callback
        Mousetrap.bind(['command+k', 'ctrl+k'], function() {
            console.log('command k or control k');
    
            // return false to prevent default browser behavior
            // and stop event from bubbling
            return false;
        });
    
        // gmail style sequences
        Mousetrap.bind('g i', function() { console.log('go to inbox'); });
        Mousetrap.bind('* a', function() { console.log('select all'); });
    
        // konami code!
        Mousetrap.bind('up up down down left right left right b a enter', function() {
            console.log('konami code');
        });
    </script>

Why Mousetrap?

There are a number of other similar libraries out there so what makes this one different?

  • There are no external dependencies, no framework is required
  • You are not limited to keydown events (You can specify keypress, keydown, or keyup or let Mousetrap choose for you).
  • 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
  • It works with international keyboard layouts
  • You can bind Gmail like key sequences in addition to regular keys and key combinations
  • You can programatically trigger key events with the trigger() method
  • It works with the numeric keypad on your keyboard
  • The code is well documented/commented

Tests

Unit tests are run with mocha.

Running in browser

View it online to check your browser compatibility. You may also download the repo and open tests/mousetrap.html in your browser.

Running with Node.js

  1. Install development dependencies

    cd /path/to/repo
    npm install
  2. Run tests

    npm test

Documentation

Full documentation can be found at https://craig.is/killing/mice

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].