umbr-key-master 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +106 -2
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,3 +1,107 @@
1
- # Key master
1
+ # KeyMaster
2
+
3
+ `KeyMaster` is a TypeScript library for managing complex keyboard shortcuts and key combinations in the browser. It allows you to register callbacks for specific key sequences, supporting all W3C/DOM-standard key types.
4
+
5
+ ---
6
+
7
+ ## Features
8
+
9
+ * Listen to single keys or combinations of multiple keys.
10
+ * Supports all standard key types, including:
11
+
12
+ * Alphabet keys (A-Z)
13
+ * Control characters (Enter, Escape, etc.)
14
+ * Modifier keys (Shift, Ctrl, Alt, Meta)
15
+ * Navigation keys (Arrow keys, Home, End, etc.)
16
+ * Function keys (F1-F12)
17
+ * Multimedia and Audio keys
18
+ * And more…
19
+ * Optional callback data via a custom function.
20
+ * Easy registration and removal of callbacks.
21
+ * Handles multiple key presses simultaneously.
22
+ * Safe cleanup of event listeners.
23
+
24
+ ---
25
+
26
+ ## Installation
27
+
28
+ ```bash
29
+ npm i umbr-key-master
30
+ ```
31
+
32
+ ---
33
+
34
+ ## Usage
35
+
36
+ ```ts
37
+ import { KeyMaster } from "umbr-key-master";
38
+ import { Alphabet, ModifierKey } from "umbr-key-master/w3";
39
+
40
+ // Optional function to provide custom data to callbacks
41
+ const getData = () => ({ user: "Alice" });
42
+
43
+ // Initialize KeyMaster
44
+ const km = new KeyMaster(getData);
45
+
46
+ // Register a key combination (Shift + A)
47
+ km.add([ModifierKey.Shift, Alphabet.A], (data) => {
48
+ console.log("Shift + A pressed!", data);
49
+ });
50
+
51
+ // Register another combination (Ctrl + B)
52
+ km.add([ModifierKey.Control, Alphabet.B], () => {
53
+ console.log("Ctrl + B pressed!");
54
+ });
55
+
56
+ // Remove a callback
57
+ const callback = (data: any) => console.log("This will be removed", data);
58
+ km.add([Alphabet.C], callback);
59
+ km.remove(callback);
60
+
61
+ // Dispose when done to clean up event listeners
62
+ km.dispose();
63
+ ```
64
+
65
+ ---
66
+
67
+ ## API
68
+
69
+ ### `constructor(getDataFunc?: () => any | Promise<any>)`
70
+
71
+ * `getDataFunc` (optional): Function that returns custom data passed to callbacks.
72
+
73
+ ### `add(targetKeys: PressableKey[], callback: KeyCallback)`
74
+
75
+ * Registers a callback for a specific key combination.
76
+ * `targetKeys`: Array of keys to listen for.
77
+ * `callback`: Function to execute when the keys are pressed.
78
+
79
+ ### `remove(callback: KeyCallback)`
80
+
81
+ * Removes a previously registered callback.
82
+
83
+ ### `dispose()`
84
+
85
+ * Cleans up all event listeners and callbacks. Call this before destroying KeyMaster.
86
+
87
+ ---
88
+
89
+ ## Key Types
90
+
91
+ The library supports all keys defined in the W3C UI Events/DOM specification. Examples include:
92
+
93
+ * `Alphabet` → A-Z
94
+ * `ControlCharacter` → Enter, Escape, Backspace, etc.
95
+ * `ModifierKey` → Shift, Control, Alt, Meta
96
+ * `NavigationKey` → ArrowUp, ArrowDown, Home, End
97
+ * `FunctionKey` → F1-F12
98
+ * `MultimediaKey` → VolumeUp, Play, Pause
99
+ * `AudioKey` → Mute, VolumeDown
100
+ * `WhitespaceKey` → Space, Tab
101
+ * And many more…
102
+
103
+ ## License
104
+
105
+ MIT © Yousaf Wazir
106
+
2
107
 
3
- A simple vanilla JS libary to handle key events and run logic
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "umbr-key-master",
3
- "version": "1.0.0",
4
- "description": "A simple key combination helper",
3
+ "version": "1.0.2",
4
+ "description": "JS library for managing complex keyboard shortcuts and key combinations in the browser",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {