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

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

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

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

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>

Others

More: https://craig.is/killing/mice

Download: mousetrap-1.5.3.zip

Mousetrap - Keyboard shortcuts in Javascript的更多相关文章

  1. OS X: Keyboard shortcuts

    Using keyboard shortcuts To use a keyboard shortcut, press a modifier key at the same time as a char ...

  2. [No0000113]Keyboard shortcuts for Windows Visual Studio Code

    General 常用Ctrl+Shift+P, F1 Show Command Palette 显示命令行Ctrl+P Quick Open, Go to File… 快速打开Ctrl+Shift+N ...

  3. keyboard shortcuts & Xcode 10

    keyboard shortcuts & Xcode 10 Xcode Keyboard Shortcuts https://swifteducation.github.io/assets/p ...

  4. MBP 2018 & Mac keyboard shortcuts

    MBP 2018 & Mac keyboard shortcuts https://support.apple.com/en-us/HT201236 delete key === Contro ...

  5. [转]UiPath Keyboard Shortcuts

    本文转自:https://docs.uipath.com/studio/docs/keyboard-shortcuts The complete list of keyboard shortcuts ...

  6. Google Chrome Keyboard Shortcuts

    Navigation To do this Press this Open a new window Ctrl + N Open a new tab Ctrl + T Open a new windo ...

  7. [转]33 useful Keyboard Shortcuts for Run commond

    原文: http://www.shortcutworld.com/en/win/Run-command.html 1. Calling Run CommandWin + r               ...

  8. SQL Server Management Studio Keyboard shortcuts

    一些平时在SQL Server Management Studio 使用到的快捷键 F5 (Ctrl+x)执行选中部分的语句,没有选中则全文执行 Ctrl+L 现实执行计划(估计) Ctrl+M 在运 ...

  9. RStudio Keyboard Shortcuts

    Console Description Windows & Linux Mac Move cursor to Console Ctrl+2 Ctrl+2 Clear console Ctrl+ ...

随机推荐

  1. HTML第九天学习笔记

    今天就继续看了下浮点float属性,代码如下: <html> <head> <title>CSS float属性</title> <meta ht ...

  2. 个推推送Android问题检测

    1.获取不到CID问题: 1.      查看配置文件是否有问题,appkey.appsecret.appid是否有空格存在. 2.      相关权限是否全部添加. 3.      manifest ...

  3. Correct thread terminate and destroy

    http://www.techques.com/question/1-3788743/Correct-thread-destroy Hello At my form I create TFrame a ...

  4. Keil MDK AGDI Drivers, ULink, JLink, ST-Link, NuLink, JTAGjet

    AGDI Drivers AGDI is an Application Program Interface (API) third-party developers can use to create ...

  5. 深入理解Oracle索引(25):一招鲜、吃遍天之单字段索引创建思路

    本文较短.不过实用性很好.还是记录之.          ㈠ 先别看SQL语句.看执行计划.挑出走全表扫的表 ㈡ 回头看SQL语句.分析上述表的约束字段有哪些.检查各个约束字段的索引是否存在 ㈢ 选择 ...

  6. Codeforces Round #335 (Div. 2) A. Magic Spheres 水题

    A. Magic Spheres Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606/ ...

  7. RMI、RPC、SOAP通讯技术介绍及比对 - XML/SOAP

    RMI.RPC.SOAP通信技术介绍及比对 1.RMI 使用java的程序员,对于RMI(RemoteMethod Invoke,远程方法调用)一定不陌生,在java中,为了在分布式应用开发时,能够方 ...

  8. 标准库 - unicode/utf8/utf8.go 解读

    // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a B ...

  9. LeetCode24 Swap Nodes in Pairs

    题意: Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1-> ...

  10. tachyon 本地模式安装

    本地模式不用考虑hadoop的版本,所以直接下载 binary 包或者自己编译 1.配置主机名.JDK.关闭防火墙.关闭Selinux.配置hosts ... ... 2.设置本机SSH免密码登陆 . ...