JavaScript utility for keyboard shortcuts.
- Download latest js-shortcut - JavaScript utility.
- viral-shortcut.js provides 4 utility functions:
viralShortcut.create()
- utility function to create new shortcutsviralShortcut.options()
- utility function to get/set options forviral-shortcut.js
viralShortcut.disable()
- utility function to disable all shortcuts created withviral-shortcut.js
viralShortcut.enable()
- utility function to enable all shortcuts created withviral-shortcut.js
-
create - utility to create shortcuts
-
Create SINGLE shortcut
Syntax:viralShortcut.create(shortcutString, handlerFunction[, delete old shortcuts=false]);
// create SINGLE shortcut and PRESERVE already created shortcuts // example: viralShortcut.create('shift + 1', function () { console.log("pressed 'shift' and '1'"); }); // create SINGLE shortcut and DELETE already created shortcuts // example: viralShortcut.create('shift + 1', function () { console.log("pressed 'shift' and '1'"); }, true);
-
Create MULTIPLE shortcuts
Syntax:viralShortcut.create(mapOfShortcutStringsAndHandlerFunctions[, delete old shortcuts=false]);
// create MULTIPLE shortcuts and PRESERVE already created shortcuts // example: viralShortcut.create({ 'q': function () { console.log("pressed 'q'"); }, 'alt+q': function () { console.log("pressed 'alt' and 'q'"); }, 'ctrl+q': function () { console.log("pressed 'ctrl' and 'q'"); }, 'shift+q': function () { console.log("pressed 'shift' and 'q'"); } }); // create MULTIPLE shortcuts and DELETE already created shortcuts // example: viralShortcut.create({ 'q': function () { console.log("pressed 'q'"); }, 'alt+q': function () { console.log("pressed 'alt' and 'q'"); }, 'ctrl+q': function () { console.log("pressed 'ctrl' and 'q'"); }, 'shift+q': function () { console.log("pressed 'shift' and 'q'"); } }, true);
-
-
options - utility function to get/set options for viral-shortcut.js
-
get options
Syntax:viralShortcut.options();
// get options for viral-shortcut.js // example: var viralShortcutOptions = viralShortcut.options(); // sample returned options object: { 'elemSelectorToSkip': '' }
-
set options
Syntax:viralShortcut.options(options);
// set options for viral-shortcut.js // example: viralShortcut.options({ 'elemSelectorToSkip': 'input[type="text"], textarea' });
-
-
disable - utility to disable all shortcuts, this will PRESERVE all created shortcuts and assigned handler functions
viralShortcut.disable();
-
enable - utility to enable all shortcuts, this will PRESERVE all created shortcuts and assigned handler functions
viralShortcut.enable();
Below are the key codes for each key. Use +
to use key combinations for shortcut (e.g. 'alt+1'
, 'ctrl + alt + delete'
).
backspace
: backspace keytab
: tab keyenter
: enter keyshift
: shift keyctrl
: control keyalt
: alter keybreak
: break keyescape
: escape key`
: back-tick keyinsert
: insert keydelete
: delete keycapsLock
: caps lock keynumLock
: num lock keyscrollLock
: scroll lock keypageUp
: page up keypageDown
: page down keyhome
: home keyend
: end keyupArrow
: up arrow keydownArrow
: down arrow keyleftArrow
: left arrow keyrightArrow
: right arrow keyleftWindowKey
: left window/command keyrightWindowKey
: right window/command keycontextMenuKey
: context menu key[
: open square bracket key]
: close square bracket key\
: back slash key/
: slash keydash
: dash key=
: equal key'
: single quote key;
: semicolon key,
: comma key.
: dot keya
: a alphbet keyb
: b alphbet keyc
: c alphbet keyd
: d alphbet keye
: e alphbet keyf
: f alphbet keyg
: g alphbet keyh
: h alphbet keyi
: i alphbet keyj
: j alphbet keyk
: k alphbet keyl
: l alphbet keym
: m alphbet keyn
: n alphbet keyo
: o alphbet keyp
: p alphbet keyq
: q alphbet keyr
: r alphbet keys
: s alphbet keyt
: t alphbet keyu
: u alphbet keyv
: v alphbet keyw
: w alphbet keyx
: x alphbet keyy
: y alphbet keyz
: z alphbet key0
: 0 digit key1
: 1 digit key2
: 2 digit key3
: 3 digit key4
: 4 digit key5
: 5 digit key6
: 6 digit key7
: 7 digit key8
: 8 digit key9
: 9 digit keynumpad0
: 0 numpad digit keynumpad1
: 1 numpad digit keynumpad2
: 2 numpad digit keynumpad3
: 3 numpad digit keynumpad4
: 4 numpad digit keynumpad5
: 5 numpad digit keynumpad6
: 6 numpad digit keynumpad7
: 7 numpad digit keynumpad8
: 8 numpad digit keynumpad9
: 9 numpad digit keynumpadAdd
: add numpad keynumpadSubtract
: substract numpad keynumpadMultiply
: multiply numpad keynumpadDivison
: slash numpad keynumpad.
: dot numpad keyf1
: f1 function keyf2
: f2 function keyf3
: f3 function keyf4
: f4 function keyf5
: f5 function keyf6
: f6 function keyf7
: f7 function keyf8
: f8 function keyf9
: f9 function keyf10
: f10 function keyf11
: f11 function keyf12
: f12 function key