Mousetrap - Keyboard shortcuts in Javascript
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的更多相关文章
- OS X: Keyboard shortcuts
Using keyboard shortcuts To use a keyboard shortcut, press a modifier key at the same time as a char ...
- [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 ...
- keyboard shortcuts & Xcode 10
keyboard shortcuts & Xcode 10 Xcode Keyboard Shortcuts https://swifteducation.github.io/assets/p ...
- MBP 2018 & Mac keyboard shortcuts
MBP 2018 & Mac keyboard shortcuts https://support.apple.com/en-us/HT201236 delete key === Contro ...
- [转]UiPath Keyboard Shortcuts
本文转自:https://docs.uipath.com/studio/docs/keyboard-shortcuts The complete list of keyboard shortcuts ...
- 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 ...
- [转]33 useful Keyboard Shortcuts for Run commond
原文: http://www.shortcutworld.com/en/win/Run-command.html 1. Calling Run CommandWin + r ...
- SQL Server Management Studio Keyboard shortcuts
一些平时在SQL Server Management Studio 使用到的快捷键 F5 (Ctrl+x)执行选中部分的语句,没有选中则全文执行 Ctrl+L 现实执行计划(估计) Ctrl+M 在运 ...
- RStudio Keyboard Shortcuts
Console Description Windows & Linux Mac Move cursor to Console Ctrl+2 Ctrl+2 Clear console Ctrl+ ...
随机推荐
- flex中DataGrid里使用itemRenderer后数据无法绑定到数据源的问题
<?xml version="1.0" encoding="utf-8"?><mx:Application xmlns:mx="ht ...
- EWARM STM32 向量表偏移设置
system_stm32f2xx.c #ifdef VECT_TAB_SRAM SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table ...
- 【转】网络中的AS自治域
1. 什么是AS自治域? 全球的互联网被分成很多个AS 自治域,每个国家的运营商.机构.甚至公司等都可以申请AS号码,AS号码是有限的,最大数目是65536.各自分配的IP地址被标清楚属于哪个AS号码 ...
- Ajax 无刷新在注册用户名时的应用的代码
var xmlHttp; uName() //用户名失去焦点时 { if(all.uname.=="") { all.l1.innerHTML="不能为空!"; ...
- Codeforces Round #336 (Div. 2)B. Hamming Distance Sum 前缀和
B. Hamming Distance Sum 题目连接: http://www.codeforces.com/contest/608/problem/A Description Genos need ...
- hdu 5286 How far away ? tarjan/lca
How far away ? Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...
- 关于MonoDevelop自动缩进的设置
monoDevelop 下载地址:http://monodevelop.com/Download 下载安装之后,可在unity Edit->Preference->External Too ...
- leanchat-android
Original: https://github.com/lzwjava/leanchat-android Backup: https://github.com/eltld/leanchat-andr ...
- SQLServer恢复表级数据
最近几天,公司的技术维护人员频繁让我恢复数据库,因为他们总是少了where条件,导致update.delete出现了无法恢复的后果,加上那些库都是几十G.恢复起来少说也要十几分钟.为此,找了一些资料和 ...
- 剑指 offer set 4 矩形覆盖
总结 1. 斐波那契数列的变形题, 但是稍有隐晦, 有点意思 2. 求解 f(3) 时, 最后一块矩形可以竖着放, 也可以两块矩形横着放, 分别对应于 f(2) 和 f(1) ------------ ...