项目作者: virallalakia

项目描述 :
JavaScript utility for keyboard shortcuts.
高级语言: HTML
项目地址: git://github.com/virallalakia/js-shortcut.git
创建时间: 2016-12-30T16:02:01Z
项目社区:https://github.com/virallalakia/js-shortcut

开源协议:MIT License

下载


js-shortcut

JavaScript utility for keyboard shortcuts.

How to use viral-shortcut.js

  • Download latest js-shortcut - JavaScript utility.
  • viral-shortcut.js provides 4 utility functions:
    • viralShortcut.create() - utility function to create new shortcuts
    • viralShortcut.options() - utility function to get/set options for viral-shortcut.js
    • viralShortcut.disable() - utility function to disable all shortcuts created with viral-shortcut.js
    • viralShortcut.enable() - utility function to enable all shortcuts created with viral-shortcut.js

Demo

Demo page on GitHub

Utility functions (Syntax and Usage)

  1. create - utility to create shortcuts

    • Create SINGLE shortcut


      Syntax: viralShortcut.create(shortcutString, handlerFunction[, delete old shortcuts=false]);

      1. // create SINGLE shortcut and PRESERVE already created shortcuts
      2. // example:
      3. viralShortcut.create('shift + 1', function () {
      4. console.log("pressed 'shift' and '1'");
      5. });
      6. // create SINGLE shortcut and DELETE already created shortcuts
      7. // example:
      8. viralShortcut.create('shift + 1', function () {
      9. console.log("pressed 'shift' and '1'");
      10. }, true);
    • Create MULTIPLE shortcuts


      Syntax: viralShortcut.create(mapOfShortcutStringsAndHandlerFunctions[, delete old shortcuts=false]);

      1. // create MULTIPLE shortcuts and PRESERVE already created shortcuts
      2. // example:
      3. viralShortcut.create({
      4. 'q': function () {
      5. console.log("pressed 'q'");
      6. },
      7. 'alt+q': function () {
      8. console.log("pressed 'alt' and 'q'");
      9. },
      10. 'ctrl+q': function () {
      11. console.log("pressed 'ctrl' and 'q'");
      12. },
      13. 'shift+q': function () {
      14. console.log("pressed 'shift' and 'q'");
      15. }
      16. });
      17. // create MULTIPLE shortcuts and DELETE already created shortcuts
      18. // example:
      19. viralShortcut.create({
      20. 'q': function () {
      21. console.log("pressed 'q'");
      22. },
      23. 'alt+q': function () {
      24. console.log("pressed 'alt' and 'q'");
      25. },
      26. 'ctrl+q': function () {
      27. console.log("pressed 'ctrl' and 'q'");
      28. },
      29. 'shift+q': function () {
      30. console.log("pressed 'shift' and 'q'");
      31. }
      32. }, true);
  2. options - utility function to get/set options for viral-shortcut.js

    • get options


      Syntax: viralShortcut.options();

      1. // get options for viral-shortcut.js
      2. // example:
      3. var viralShortcutOptions = viralShortcut.options();
      4. // sample returned options object:
      5. {
      6. 'elemSelectorToSkip': ''
      7. }
    • set options


      Syntax: viralShortcut.options(options);

      1. // set options for viral-shortcut.js
      2. // example:
      3. viralShortcut.options({
      4. 'elemSelectorToSkip': 'input[type="text"], textarea'
      5. });
  3. disable - utility to disable all shortcuts, this will PRESERVE all created shortcuts and assigned handler functions

    1. viralShortcut.disable();
  4. enable - utility to enable all shortcuts, this will PRESERVE all created shortcuts and assigned handler functions

    1. viralShortcut.enable();

Shortcut codes for viral-shortcut.js

Below are the key codes for each key. Use + to use key combinations for shortcut (e.g. 'alt+1', 'ctrl + alt + delete').

  • backspace: backspace key
  • tab: tab key
  • enter: enter key
  • shift: shift key
  • ctrl: control key
  • alt: alter key
  • break: break key
  • escape: escape key
  • ` : back-tick key
  • insert: insert key
  • delete: delete key
  • capsLock: caps lock key
  • numLock: num lock key
  • scrollLock: scroll lock key
  • pageUp: page up key
  • pageDown: page down key
  • home: home key
  • end: end key
  • upArrow: up arrow key
  • downArrow: down arrow key
  • leftArrow: left arrow key
  • rightArrow: right arrow key
  • leftWindowKey: left window/command key
  • rightWindowKey: right window/command key
  • contextMenuKey: context menu key
  • [: open square bracket key
  • ]: close square bracket key
  • \: back slash key
  • /: slash key
  • dash: dash key
  • =: equal key
  • ': single quote key
  • ;: semicolon key
  • ,: comma key
  • .: dot key
  • a: a alphbet key
  • b: b alphbet key
  • c: c alphbet key
  • d: d alphbet key
  • e: e alphbet key
  • f: f alphbet key
  • g: g alphbet key
  • h: h alphbet key
  • i: i alphbet key
  • j: j alphbet key
  • k: k alphbet key
  • l: l alphbet key
  • m: m alphbet key
  • n: n alphbet key
  • o: o alphbet key
  • p: p alphbet key
  • q: q alphbet key
  • r: r alphbet key
  • s: s alphbet key
  • t: t alphbet key
  • u: u alphbet key
  • v: v alphbet key
  • w: w alphbet key
  • x: x alphbet key
  • y: y alphbet key
  • z: z alphbet key
  • 0: 0 digit key
  • 1: 1 digit key
  • 2: 2 digit key
  • 3: 3 digit key
  • 4: 4 digit key
  • 5: 5 digit key
  • 6: 6 digit key
  • 7: 7 digit key
  • 8: 8 digit key
  • 9: 9 digit key
  • numpad0: 0 numpad digit key
  • numpad1: 1 numpad digit key
  • numpad2: 2 numpad digit key
  • numpad3: 3 numpad digit key
  • numpad4: 4 numpad digit key
  • numpad5: 5 numpad digit key
  • numpad6: 6 numpad digit key
  • numpad7: 7 numpad digit key
  • numpad8: 8 numpad digit key
  • numpad9: 9 numpad digit key
  • numpadAdd: add numpad key
  • numpadSubtract: substract numpad key
  • numpadMultiply: multiply numpad key
  • numpadDivison: slash numpad key
  • numpad.: dot numpad key
  • f1: f1 function key
  • f2: f2 function key
  • f3: f3 function key
  • f4: f4 function key
  • f5: f5 function key
  • f6: f6 function key
  • f7: f7 function key
  • f8: f8 function key
  • f9: f9 function key
  • f10: f10 function key
  • f11: f11 function key
  • f12: f12 function key