KikeyJS is an easy-to-use shortcut library designed for simple event handling, supporting key sequences and shortcut recording. For an interactive introduction, visit the KikeyJS homepage: https://fobshippingpoint.github.io/kikey/.
KikeyJS provides UMD and ES Module formats.
<!doctype html>
<html>
<head>
<script src="https://unpkg.com/kikey/dist/umd/kikey.min.js"></script>
</head>
<body>
<script>
const kikey = Kikey.createKikey();
</script>
</body>
</html>
<!doctype html>
<html>
<body>
<script type="module">
import { createKikey } from "https://unpkg.com/kikey/dist/index.js";
const kikey = createKikey();
</script>
</body>
</html>
npm install kikey
deno add @cclan/kikey
KikeyJS provides a very simple API for key binding, event handling, and recording:
// Key registration
const notice = () => alert("You pressed Ctrl+S");
kikey.on("C-s", notice);
// Unregistration
kikey.off(notice);
// Supports key sequences (chains)
kikey.on("A-l l f o r o n e", () => console.log("You pressed Alt+L → L → F → O → R → O → N → E"));
// Key sequence recording
kikey.startRecord();
// ...user presses key strokes...
// Stop recording and obtain the key binding sequence string for user customization
const sequence = kikey.stopRecord();
Creates a KikeyJS object that listens for keypress and keyup events on the specified targetElement
. If no element is provided, it defaults to document
.
Binds a key sequence to a specified callback function. When the sequence is pressed in the correct order, the callback function is triggered.
sequence
: The key sequence, which can be a single key, a combination of keys with modifiers like Ctrl, Shift, Alt, Meta concatenated with a dash (-
), or a series of key bindings separated by whitespace.callback
: The callback function, which does not receive any arguments.
onComplete
: Fired when the entire sequence is pressed correctly.onComboChange
(optional): A callback function for a series of key bindings. When a keyboard event is fired,onComboChange
notifies the client of the currentcombo
of the key sequence.combo=0
indicates that the combo has been broken.
Remove binding for certain callback function.
A one-time version of on
.
Update key sequence by callback.
Enable kikey.
Disable kikey.
Destroy kikey instance, will remove all listeners.
Start shortcut recording.
Stop shortcut recording.
Parse kikey-style key binding (e.g. C-a
) and returns an object structured as follows:
{
ctrlKey: true,
shiftKey: false,
altKey: false,
metaKey: false,
key: "a"
}
Suitable for the displaying the recorded shortcuts to users.
Original Key | Notation |
---|---|
Ctrl | C |
Shift | S |
Alt | A |
Meta | M |
KikeyJS supports modifiers. Use a dash (-
) to concatenate strokes to form a single key binding. For example, C
and S-o
are both key bindings, as is C-S-A-M-p
.
Keys with a character length greater than 1 are classified as Special Keys. This includes space
and dash
, which are used as key sequence delimiters.
- space
- dash
- arrowleft
- arrowright
- arrowup
- arrowdown
- backspace
- enter
- escape
- capslock
- tab
- home
- pageup
- pagedown
- end
- f1
- f2
- f3
- f4
- f5
- f6
- f7
- f8
- f9
- f10
- f11
- f12