• View our reviews on Hot Scripts
  • JS Tutorial

Recent Comments

Powered by Disqus

Back to articles

Multiple key combinations using javascript

Keyboard Shortcut class can be used to bind functions to custom key combinations.

It is also possible to provide interval for callback function to be recalled (until releasing key combination), if key combination was pressed and held.

Package contains kb_shortcut.js and kb_shortcut.packed.js (packed javascript)and 3 example files: simple_example.html (showing example of how to bind function to custom key combination), example.html (possible usages of this class) and squario.html(some sort of Mario game parody, using square div as Mario).



Example codes

<h1 style='text-align: center;'>Just try pressing Ctr+Alt+A</h1>
<script type="text/javascript" src="./kb_shortcut.js" ></script>
<script type="text/javascript">
var kb = new kb_shortcut();
kb.add(["Ctrl", "Alt", "A"], function(){
    alert("Key combination activated");

Examples in action

Example scripts provided with package in action:

Method list


Back to method list

Method namenew kb_shortcut()
DescriptionCreate Keyboard Shortcut instance

Bind function to key combination

Back to method list

Method nameadd(keys, callback, hold, stop)
DescriptionAdds provided function to provided keyboard combination using provided configuration
Input parameters

string or array keys - One key/button name as string or multiple keys/buttons as arrays

function callback - which function to call, when provided combination is pressed

int hold (optional) - how often to call callback function if combination is pressed and not released (default: 0, disables repeated calls)

bool stop - try to prevent default event behavoir. It is only possible to prevent in website events, not browser defined events. (default: false)

Supported Key/Button values

List of all key/button names, that can be passed to add method creating key combinations

LettersA - ZG
Numbers0 - 93
Function keysF1 - F12F7
Space keySpaceSpace
Enter/Return keyEnterEnter
Tab keyTabTab
Backspace keyBackspaceBackspace
Shift keyShiftShift
Control keyCtrlCtrl
Alt keyAltAlt
Caps Lock keyCaps LockCaps Lock
Num Lock keyNum LockNum Lock
ArrowsUp, Right, Down, LeftRight
Insert keyInsIns
Delete keyDelDel
Home keyHomeHome
End keyEndEnd
Page up keyPage upPage up
Page down keyPage downPage down
Other symbols"+", "-", "*", "/", ";", "=", ",", ".", "`", "[", "", "]", "'"=

Latest changes

None for now

Rate us

Like our script? Rate it at JavaScript > Hot Scripts

Try it out and Rate on


JS classes support forum or comments below

You may also be interested in:

Powered by

blog comments powered by Disqus