KeyboardJS - "构建你的应用吧,我会处理按键"

简介: KeyboardJS  - "构建你的应用吧,我会处理按键"太阳火神的美丽人生 (http://blog.csdn.net/opengl_es)本文遵循“署名-非商业用途-保持一致”创作公用协议转载请保留此句:太阳火神的美丽人生 -  本博客专注于 敏捷开发及移动和物联设备研究:iOS、Android、Html5、Arduino、pcDuino,否则,出自本博客的文章拒绝转载或再转载,谢谢合作。

KeyboardJS  - "构建你的应用吧,我会处理按键"

太阳火神的美丽人生 (http://blog.csdn.net/opengl_es)

本文遵循“署名-非商业用途-保持一致”创作公用协议

转载请保留此句:太阳火神的美丽人生 -  本博客专注于 敏捷开发及移动和物联设备研究:iOS、Android、Html5、Arduino、pcDuino否则,出自本博客的文章拒绝转载或再转载,谢谢合作。



KeyboardJS

"Build your app, I'll handle the keys."

Demo

command, windows, win, super, leftcommand, leftwindows, leftwin, leftsuper, c

What is KeyboardJS?

A JavaScript library for binding keyboard combos without the pain of key codes and key combo conflicts. It can be used as both a standalone library or an AMD module (see  RequireJS for details).

Get it Here

Language Support

KeyboardJS can support any locale, however out of the box it just comes with the US locale (for now). Adding a new locale is easy. Map your keyboard to an object and pass it to KeyboardJS.locale.register(localeName, localeDefinition) then call KeyboardJS.locale(localeName). 

If you create a new locale please consider sending me a pull request or submit it to the  issue tracker so I can add it to the library.

Methods

KeyboardJS.on

Usage

KeyboardJS.on(keyCombo, onDownCallback, onUpCallback);
Binds any key or key combo. See 'keyCombo' definition below for details. The onDownCallback is fired once the key or key combo becomes active. The onUpCallback is fired when the combo no longer active (a single key is released). 

Both the onUpCallback and the onUpCallback are passed three arguments. The first is the key event, the second is the keys pressed, and the third is the key combo string.

Returned

  • clear() - Removes the key or key combo binding.
  • on() - Allows you to bind to the keyup and keydown event of the given combo. An alternative to adding the onDownCallback and onUpCallback.

KeyboardJS.activeKeys

Usage

KeyboardJS.activeKeys();
Returns an array of active keys by name.

Returned

Returns an array of key names that are currently being pressed.

KeyboardJS.clear

Usage

KeyboardJS.clear(keyCombo);
Removes all bindings with the given key combo. See 'keyCombo' definition for more details. 

Please note that if you are just trying to remove a single binding should use the clear method in the object returned by KeyboardJS.on instead of this. This function is for removing all binding that use a certain key.

KeyboardJS.clear.key

Usage

KeyboardJS.clear.key(key);
Removes all bindings that use the given key.

KeyboardJS.locale

Usage

KeyboardJS.locale(localeName);
Changes the locale keyboardJS uses to map key presses. Out of the box KeyboardJS only supports US keyboards, however it is possible to add additional locales via KeyboardJS.locale.register()

KeyboardJS.locale.register

Usage

KeyboardJS.locale.register(localeName, localeDefinition);
Adds new locale definitions to KeyboardJS.

Definitions

keyCombo

A string containing key names separated by whitespace,  >+, and  ,.

examples

  • 'a' - binds to the 'a' key. Pressing 'a' will match this keyCombo.
  • 'a, b' - binds to the 'a' and 'b' keys. Pressing either of these keys will match this keyCombo.
  • 'a b' - binds to the 'a' and 'b' keys. Pressing either of these keys will match this keyCombo.
  • 'a + b' - binds to the 'a' and 'b' keys. Pressing both of these keys will match this keyCombo.
  • 'a > b' - binds to the 'a' and 'b' keys. Pressing 'a' then 'b' will match this keyCombo.
  • 'a + b, c + d' - binds to the 'a', 'b', 'c' and 'd' keys. Pressing either the 'a' key and the 'b' key, or the 'c' and the 'd' key will match this keyCombo.
  • 'a + b > c + d' - binds to the 'a', 'b', 'c' and 'd' keys. Pressing both the 'a' key and the 'b' key, then both the 'c' and the 'd' key will match this keyCombo.

localeDefinitions

An object that maps keyNames to their keycode and stores locale specific macros. Used for mapping keys on different locales.

examples

  • { "map": { "65": ["a"], "66": ["b"], ... }, "macros": [ ["shift + `", ["tilde", "~"]], ["shift + 1", ["exclamation", "!"]], .... ] }

Credits

I ( Robert Hurst) made this to enable better access to key controls in my applications. I'd like to share it with fellow devs. Feel free to fork this project and make your own changes.




目录
相关文章
|
8月前
|
JavaScript 编译器
模块 ""element-plus"" 没有导出的成员 "ElMessage"。你是想改用 "import ElMessage from "element-plus"" 吗?
模块 ""element-plus"" 没有导出的成员 "ElMessage"。你是想改用 "import ElMessage from "element-plus"" 吗?
225 0
|
JavaScript
理解JS函数调用和"this"
如果理解核心函数的调用机制,同时验证一些以核心函数为基础的其他实现方式的运行机制,关于上述所说的问题就会迎刃而解。
关于$(":button") 选择器的理解
关于$(":button") 选择器的理解
276 0
|
自然语言处理
合同结构化文书解析失败,请联系管理员排查:{"code":3001,"message":"File transform error","success":false,"tracerId":"requestId"}报错处理
在使用自然语言处理自学习平台时,标注任务需要上传标注数据,但是使用doc格式上传文件后开始标注时出现了此提示,此篇文章简单介绍下此问题的处理方式。
609 0
合同结构化文书解析失败,请联系管理员排查:{"code":3001,"message":"File transform error","success":false,"tracerId":"requestId"}报错处理
OPA 12 - oButton.$().trigger("tap")
Created by Wang, Jerry, last modified on Nov 08, 2015
99 0
OPA 12 - oButton.$().trigger("tap")
【MUI】HBuilder class="mui-switch"开关监听
转载请注明出处:http://blog.csdn.net/qq_26525215 本文源自【大学之旅_谙忆的博客】 如何对MUI中的switch开关按钮进行监听, 页面代码如下: 自动登录 ...
1321 0
|
Android开发 HTML5 移动开发
什么是 "署名-非商业性使用-相同方式共享"
什么是 "署名-非商业性使用-相同方式共享" 太阳火神的美丽人生 (http://blog.csdn.net/opengl_es) 本文遵循“署名-非商业用途-保持一致”创作公用协议 转载请保留此句:太阳火神的美丽人生 -  本博客专注于 敏捷开发及移动和物联设备研究:iOS、Android、Html5、Arduino、pcDuino,否则,出自本博客的文章拒绝转载或再转载,谢谢合作。
1540 0