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.
Contents
- Download
- Example codes
- Examples in action
- Method list
- Supported Key/Button values
- Latest changes
- Rate us
- Support
Download
Example codes
<html> <head> </head> <body> <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"); }) </script> </body> </html>
Examples in action
Example scripts provided with package in action:
Method list
Constructor
| Method name | new kb_shortcut() |
| Description | Create Keyboard Shortcut instance |
Bind function to key combination
| Method name | add(keys, callback, hold, stop) |
| Description | Adds 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
| Description | Values | Example |
| Letters | A - Z | G |
| Numbers | 0 - 9 | 3 |
| Function keys | F1 - F12 | F7 |
| Space key | Space | Space |
| Enter/Return key | Enter | Enter |
| Tab key | Tab | Tab |
| Backspace key | Backspace | Backspace |
| Shift key | Shift | Shift |
| Control key | Ctrl | Ctrl |
| Alt key | Alt | Alt |
| Caps Lock key | Caps Lock | Caps Lock |
| Num Lock key | Num Lock | Num Lock |
| Arrows | Up, Right, Down, Left | Right |
| Insert key | Ins | Ins |
| Delete key | Del | Del |
| Home key | Home | Home |
| End key | End | End |
| Page up key | Page up | Page up |
| Page down key | Page down | Page down |
| Other symbols | "+", "-", "*", "/", ";", "=", ",", ".", "`", "[", "", "]", "'" | = |
Latest changes
None for now
Rate us
Try it out and Rate on JSclasses.org
Support
JS classes support forum or comments below
You may also be interested in:
Powered by BlogAlike.com










