KeyboardJS - "構建你的應用吧,我會處理按鍵"

來源:互聯網
上載者:User

標籤:android   des   style   blog   http   java   

KeyboardJS  - "構建你的應用吧,我會處理按鍵"

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

本文遵循“署名-非商業用途-保持一致”創作公用協議

轉載請保留此句:太陽火神的美麗人生 -  本部落格專註於 敏捷開發及移動和物聯裝置研究:iOS、Android、Html5、Arduino、pcDuino,否則,出自本部落格的文章拒絕轉載或再轉載,謝謝合作。



KeyboardJS"Build your app, I‘ll handle the keys."Democommand, windows, win, super, leftcommand, leftwindows, leftwin, leftsuper, cWhat 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 HereDownload KeyboardJSLanguage SupportKeyboardJS 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.MethodsKeyboardJS.onUsageKeyboardJS.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.activeKeysUsageKeyboardJS.activeKeys();Returns an array of active keys by name.ReturnedReturns an array of key names that are currently being pressed.KeyboardJS.clearUsageKeyboardJS.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.keyUsageKeyboardJS.clear.key(key);Removes all bindings that use the given key.KeyboardJS.localeUsageKeyboardJS.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.registerUsageKeyboardJS.locale.register(localeName, localeDefinition);Adds new locale definitions to KeyboardJS.DefinitionskeyComboA 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.
localeDefinitionsAn 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", "!"]], .... ] }
CreditsI (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.




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.