@@ -186,6 +186,8 @@ hotkeys('ctrl-y, ctrl-a', {splitKey: '-'}, function(e){
186
186
- ` element<HTMLElement> `
187
187
- ` keyup<Boolean> `
188
188
- ` keydown<Boolean> `
189
+ - ` splitKey<string> ` (默认值 ` + ` )
190
+ - ` capture<Boolean> `
189
191
190
192
``` js
191
193
hotkeys (' o, enter' , {
@@ -194,9 +196,70 @@ hotkeys('o, enter', {
194
196
}, function (){
195
197
console .log (' do something else' );
196
198
});
199
+
200
+ hotkeys (' ctrl-+' , { splitKey: ' -' }, function (e ) {
201
+ console .log (' you pressed ctrl and +' );
202
+ });
203
+
204
+ hotkeys (' +' , { splitKey: ' -' }, function (e ){
205
+ console .log (' you pressed +' );
206
+ })
207
+ ```
208
+
209
+ ** keyup**
210
+
211
+ ** key down** 和 ** key up** 将都执行回调事件。
212
+
213
+ ``` js
214
+ hotkeys (' ctrl+a,alt+a+s' , { keyup: true }, (evn , handler ) => {
215
+ if (evn .type === ' keydown' ) {
216
+ console .log (' keydown:' , evn .type , handler, handler .key );
217
+ }
218
+ if (evn .type === ' keyup' ) {
219
+ console .log (' keyup:' , evn .type , handler, handler .key );
220
+ }
221
+ });
222
+ ```
223
+
224
+ ## API 参考
225
+
226
+ ### 星号 *
227
+
228
+ 通过修饰符号判断
229
+
230
+ ``` js
231
+ hotkeys (' *' , function () {
232
+ if (hotkeys .shift ) {
233
+ console .log (' shift is pressed!' );
234
+ }
235
+
236
+ if (hotkeys .ctrl ) {
237
+ console .log (' ctrl is pressed!' );
238
+ }
239
+
240
+ if (hotkeys .alt ) {
241
+ console .log (' alt is pressed!' );
242
+ }
243
+
244
+ if (hotkeys .option ) {
245
+ console .log (' option is pressed!' );
246
+ }
247
+
248
+ if (hotkeys .control ) {
249
+ console .log (' control is pressed!' );
250
+ }
251
+
252
+ if (hotkeys .cmd ) {
253
+ console .log (' cmd is pressed!' );
254
+ }
255
+
256
+ if (hotkeys .command ) {
257
+ console .log (' command is pressed!' );
258
+ }
259
+ });
197
260
```
198
261
199
- ## 切换快捷键
262
+ ### 切换快捷键
200
263
201
264
如果在单页面在不同的区域,相同的快捷键,干不同的事儿,之间来回切换。O(∩_ ∩)O !
202
265
@@ -218,7 +281,7 @@ hotkeys('ctrl+o, enter', 'scope2', function(){
218
281
hotkeys .setScope (' scope1' ); // 默认所有事儿都干哦
219
282
```
220
283
221
- ## 标记快捷键范围
284
+ ### 标记快捷键范围
222
285
223
286
** 删除** 区域范围标记
224
287
@@ -238,20 +301,19 @@ hotkeys.getScope();
238
301
hotkeys .setScope (' scope1' );
239
302
```
240
303
241
- ## trigger
304
+ ### trigger
242
305
243
306
``` js
244
307
hotkeys .trigger (' ctrl+o' )
245
308
hotkeys .trigger (' ctrl+o' , ' scope2' )
246
309
```
247
310
248
- ## 解除绑定
311
+ ### 解除绑定
249
312
250
313
` hotkeys.unbind() ` 解除绑定的所有快捷键
251
314
` hotkeys.unbind("ctrl+o, ctrl+alt+enter") ` 解除绑定两组快捷键
252
315
` hotkeys.unbind("ctrl+o","files") ` 解除绑定名字叫files的区域范围中的一组快捷键
253
316
254
-
255
317
``` js
256
318
// 解除绑定 'a' 程序函数
257
319
hotkeys .unbind (' a' );
@@ -272,14 +334,20 @@ hotkeys.unbind('a', example);
272
334
hotkeys (' a' , ' issues' , example);
273
335
hotkeys .unbind (' a' , ' issues' , example);
274
336
```
275
- ``` js
337
+
276
338
可以通过传入对象解除绑定的快捷键
339
+
340
+ ``` js
277
341
hotkeys .unbind ({
278
342
key: ' ctrl-e,ctrl-u' ,
279
343
scope: ' issues' ,
280
344
spitKey: ' -'
281
345
})
346
+ ```
347
+
282
348
传入数组可同时解除多个scope下绑定的快捷键
349
+
350
+ ``` js
283
351
hotkeys .unbind ([
284
352
{
285
353
key: ' a, ctrl+r' ,
@@ -293,7 +361,7 @@ hotkeys.unbind([
293
361
])
294
362
```
295
363
296
- ## 键判断
364
+ ### isPressed
297
365
298
366
判断摁下的键是否为某个键
299
367
@@ -305,7 +373,7 @@ hotkeys('a', function(){
305
373
});
306
374
```
307
375
308
- ## 获取摁下键值
376
+ ### getPressedKeyCodes
309
377
310
378
获取摁下绑定键的键值 ` hotkeys.getPressedKeyCodes() `
311
379
@@ -315,22 +383,32 @@ hotkeys('command+ctrl+shift+a,f', function(){
315
383
})
316
384
```
317
385
318
- ## keyup
386
+ ### getPressedKeyString
319
387
320
- ** key down ** 和 ** key up ** 将都执行回调事件。
388
+ 获取所有注册代码的列表
321
389
322
390
``` js
323
- hotkeys (' ctrl+a,alt+a+s' , { keyup: true }, (evn , handler ) => {
324
- if (evn .type === ' keydown' ) {
325
- console .log (' keydown:' , evn .type , handler, handler .key );
326
- }
327
- if (evn .type === ' keyup' ) {
328
- console .log (' keyup:' , evn .type , handler, handler .key );
329
- }
330
- });
391
+ hotkeys (' command+ctrl+shift+a,f' , function () {
392
+ console .log (hotkeys .getPressedKeyString ()); // => ['⌘', '⌃', '⇧', 'A', 'F']
393
+ })
394
+ ```
395
+
396
+
397
+ ### getAllKeyCodes
398
+
399
+ Get a list of all registration codes.
400
+
401
+ ``` js
402
+ hotkeys (' command+ctrl+shift+a,f' , function () {
403
+ console .log (hotkeys .getAllKeyCodes ());
404
+ // [
405
+ // { scope: 'all', shortcut: 'command+ctrl+shift+a', mods: [91, 17, 16], keys: [91, 17, 16, 65] },
406
+ // { scope: 'all', shortcut: 'f', mods: [], keys: [42] }
407
+ // ]
408
+ })
331
409
```
332
410
333
- ## 过滤
411
+ ### filter
334
412
335
413
` INPUT ` ` SELECT ` ` TEXTAREA ` 默认不处理。
336
414
` hotkeys.filter ` 返回 ` true ` 快捷键设置才会起作用,` false ` 快捷键设置失效。
0 commit comments