You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
Go to file
jaywcjlove d1b0b700b4 update API documentation. 10 years ago
build build hotkeys 10 years ago
src Add unbind method . 10 years ago
test add hotkeys 10 years ago
.gitignore add hotkeys 10 years ago
Gruntfile.coffee build hotkeys 10 years ago
README.md update API documentation. 10 years ago
bower.json add bower 10 years ago
package.json update 10 years ago

README.md

设置快捷键

这又是在重复造轮子,呵呵~

下载

bower

Run bower info hotkeysjs to list the available versions.
下载 bower install hotkeysjs

npm

下载 npm install hotkeys-js

定义快捷键

// 定义a快捷键
hotkeys('a', function(){ alert('你按下了 a!') });

// 返回false将停止活动并阻止默认浏览器事件
hotkeys('ctrl+r', function(){ alert('停止刷新!'); return false });

// 多个快捷方式做同样的事情
hotkeys('⌘+r, ctrl+r', function(){ });

支持的键

, shift, option, , alt, ctrl, control, command,

Command()
Control
Option(alt)
Shift
Caps Lock(大写)
fn 功能键就是fn
↩︎ return/Enter

修饰键判断

可以对下面的修饰键判断 shift alt option ctrl control command

if(hotkeys.shift) console.log('大哥你摁下了shift键');

切换快捷键

// 一个快捷键,有可能干的活儿不一样哦
hotkeys('ctrl+o, ctrl+alt+enter', 'issues', function(){
    console.log('干点活儿');
});
hotkeys('o, enter', 'files', function(){ 
    console.log('另一种活儿');
});

// 设定范围scope 
hotkeys.setScope('issues'); // 默认所有事儿都干哦 

解除绑定

hotkeys.unbind("ctrl+o, ctrl+alt+enter") 解除绑定两组快捷键
hotkeys.unbind("ctrl+o","files") 解除绑定名字叫files钟的一组快捷键

键判断

判断摁下的键是否为某个键

hotkeys('a', function(){
    console.log(hotkeys.isPressed("A")); //=> true
    console.log(hotkeys.isPressed(65)); //=> true
});

获取摁下键值

获取摁下绑定键的键值

hotkeys('command+ctrl+shift+a,f', function(){
    console.log(hotkeys.getPressedKeyCodes()); //=> [17, 65] 或者 [70]
})

兼容模式

var k = hotkeys.noConflict();
k('a', function() {
    console.log("这里可以干一些事儿")
});

hotkeys()
// -->Uncaught TypeError: hotkeys is not a function(anonymous function) 
// @ VM2170:2InjectedScript._evaluateOn 
// @ VM2165:883InjectedScript._evaluateAndWrap 
// @ VM2165:816InjectedScript.evaluate @ VM2165:682