macromate-hid 1.0.0-beta.1

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.
@@ -0,0 +1,338 @@
1
+ /**
2
+ * TypeScript declarations for macromate-hid
3
+ */
4
+
5
+ export interface ControllerOptions {
6
+ /** Vendor ID (default: 0xCAFE) */
7
+ vid?: number;
8
+ /** Product ID (default: 0x4010) */
9
+ pid?: number;
10
+ /** Default command timeout in ms (default: 2000) */
11
+ timeout?: number;
12
+ /** Enable debug logging (default: false) */
13
+ debug?: boolean;
14
+ }
15
+
16
+ export interface CommandResult {
17
+ /** Status code (0 = OK) */
18
+ status: number;
19
+ /** Response data buffer */
20
+ data: Buffer;
21
+ }
22
+
23
+ export interface PingResult {
24
+ /** Firmware version string */
25
+ version: string;
26
+ }
27
+
28
+ export interface DeviceInfo {
29
+ vendorId: number;
30
+ productId: number;
31
+ path: string;
32
+ product?: string;
33
+ manufacturer?: string;
34
+ usagePage?: number;
35
+ usage?: number;
36
+ interface: number;
37
+ }
38
+
39
+ /**
40
+ * Main class for communicating with MacroMate device
41
+ */
42
+ export class MacroController {
43
+ /** Vendor ID */
44
+ readonly vid: number;
45
+ /** Product ID */
46
+ readonly pid: number;
47
+ /** Default timeout (ms) */
48
+ readonly timeout: number;
49
+ /** Debug mode enabled */
50
+ readonly debug: boolean;
51
+ /** Check if device is connected */
52
+ readonly isConnected: boolean;
53
+ /** Device info (after connection) */
54
+ readonly deviceInfo: DeviceInfo | null;
55
+
56
+ constructor(options?: ControllerOptions);
57
+
58
+ /**
59
+ * Find all matching devices
60
+ */
61
+ static findDevices(vid?: number, pid?: number): DeviceInfo[];
62
+
63
+ /**
64
+ * List all HID devices with the specified VID
65
+ */
66
+ static listDevices(vid?: number): DeviceInfo[];
67
+
68
+ /**
69
+ * Connect to the device
70
+ * @throws Error if device not found or connection failed
71
+ */
72
+ connect(): boolean;
73
+
74
+ /**
75
+ * Disconnect from the device
76
+ */
77
+ disconnect(): void;
78
+
79
+ /**
80
+ * Send a raw command to the device
81
+ */
82
+ sendCommand(cmd: number, args?: number[], options?: { timeout?: number }): Promise<CommandResult>;
83
+
84
+ /**
85
+ * Send command without waiting for response (for bootloader)
86
+ */
87
+ sendCommandNoWait(cmd: number, args?: number[]): void;
88
+
89
+ // High-level API
90
+
91
+ /**
92
+ * Ping the device
93
+ * @returns Firmware version info
94
+ */
95
+ ping(): Promise<PingResult>;
96
+
97
+ /**
98
+ * Get firmware version
99
+ * @returns Version string (e.g., "1.0.0")
100
+ */
101
+ getVersion(): Promise<string>;
102
+
103
+ /**
104
+ * Enter bootloader mode (device will reboot)
105
+ * Connection will be lost after this command
106
+ */
107
+ enterBootloader(): void;
108
+
109
+ // Keyboard API
110
+
111
+ /**
112
+ * Press a key (and hold)
113
+ */
114
+ keyPress(keycode: number): Promise<void>;
115
+
116
+ /**
117
+ * Release a key
118
+ */
119
+ keyRelease(keycode: number): Promise<void>;
120
+
121
+ /**
122
+ * Tap a key (press and release)
123
+ */
124
+ keyTap(keycode: number): Promise<void>;
125
+
126
+ /**
127
+ * Set modifier keys (Ctrl, Shift, Alt, Win)
128
+ * @param modifiers Modifier flags (use MOD constants, can be combined with |)
129
+ */
130
+ setModifiers(modifiers: number): Promise<void>;
131
+
132
+ /**
133
+ * Release all keys and modifiers
134
+ */
135
+ releaseAll(): Promise<void>;
136
+
137
+ /**
138
+ * Type a string (ASCII only)
139
+ * @param text Text to type (max 62 characters per call)
140
+ */
141
+ typeString(text: string): Promise<void>;
142
+
143
+ /**
144
+ * Execute a keyboard shortcut (e.g., Ctrl+C)
145
+ */
146
+ shortcut(modifiers: number, keycode: number): Promise<void>;
147
+
148
+ // Mouse API
149
+
150
+ /**
151
+ * Move mouse relative to current position
152
+ * @param x X movement (-127 to 127)
153
+ * @param y Y movement (-127 to 127)
154
+ */
155
+ mouseMove(x: number, y: number): Promise<void>;
156
+
157
+ /**
158
+ * Click a mouse button
159
+ */
160
+ mouseClick(button?: number): Promise<void>;
161
+
162
+ /**
163
+ * Press a mouse button (and hold)
164
+ */
165
+ mousePress(button?: number): Promise<void>;
166
+
167
+ /**
168
+ * Release a mouse button
169
+ */
170
+ mouseRelease(button?: number): Promise<void>;
171
+
172
+ /**
173
+ * Scroll the mouse wheel
174
+ * @param amount Scroll amount (positive = up, negative = down)
175
+ */
176
+ mouseScroll(amount: number): Promise<void>;
177
+
178
+ /**
179
+ * Double-click a mouse button
180
+ */
181
+ mouseDoubleClick(button?: number, delay?: number): Promise<void>;
182
+
183
+ // Utility
184
+
185
+ /**
186
+ * Execute device-side delay
187
+ */
188
+ delay(ms: number): Promise<void>;
189
+ }
190
+
191
+ // HID Keycodes
192
+ export const KEY: {
193
+ readonly A: number;
194
+ readonly B: number;
195
+ readonly C: number;
196
+ readonly D: number;
197
+ readonly E: number;
198
+ readonly F: number;
199
+ readonly G: number;
200
+ readonly H: number;
201
+ readonly I: number;
202
+ readonly J: number;
203
+ readonly K: number;
204
+ readonly L: number;
205
+ readonly M: number;
206
+ readonly N: number;
207
+ readonly O: number;
208
+ readonly P: number;
209
+ readonly Q: number;
210
+ readonly R: number;
211
+ readonly S: number;
212
+ readonly T: number;
213
+ readonly U: number;
214
+ readonly V: number;
215
+ readonly W: number;
216
+ readonly X: number;
217
+ readonly Y: number;
218
+ readonly Z: number;
219
+ readonly N1: number;
220
+ readonly N2: number;
221
+ readonly N3: number;
222
+ readonly N4: number;
223
+ readonly N5: number;
224
+ readonly N6: number;
225
+ readonly N7: number;
226
+ readonly N8: number;
227
+ readonly N9: number;
228
+ readonly N0: number;
229
+ readonly ENTER: number;
230
+ readonly ESC: number;
231
+ readonly BACKSPACE: number;
232
+ readonly TAB: number;
233
+ readonly SPACE: number;
234
+ readonly MINUS: number;
235
+ readonly EQUAL: number;
236
+ readonly BRACKET_LEFT: number;
237
+ readonly BRACKET_RIGHT: number;
238
+ readonly BACKSLASH: number;
239
+ readonly SEMICOLON: number;
240
+ readonly QUOTE: number;
241
+ readonly GRAVE: number;
242
+ readonly COMMA: number;
243
+ readonly PERIOD: number;
244
+ readonly SLASH: number;
245
+ readonly CAPS_LOCK: number;
246
+ readonly F1: number;
247
+ readonly F2: number;
248
+ readonly F3: number;
249
+ readonly F4: number;
250
+ readonly F5: number;
251
+ readonly F6: number;
252
+ readonly F7: number;
253
+ readonly F8: number;
254
+ readonly F9: number;
255
+ readonly F10: number;
256
+ readonly F11: number;
257
+ readonly F12: number;
258
+ readonly PRINT_SCREEN: number;
259
+ readonly SCROLL_LOCK: number;
260
+ readonly PAUSE: number;
261
+ readonly INSERT: number;
262
+ readonly HOME: number;
263
+ readonly PAGE_UP: number;
264
+ readonly DELETE: number;
265
+ readonly END: number;
266
+ readonly PAGE_DOWN: number;
267
+ readonly RIGHT: number;
268
+ readonly LEFT: number;
269
+ readonly DOWN: number;
270
+ readonly UP: number;
271
+ readonly NUM_LOCK: number;
272
+ readonly NUMPAD_SLASH: number;
273
+ readonly NUMPAD_ASTERISK: number;
274
+ readonly NUMPAD_MINUS: number;
275
+ readonly NUMPAD_PLUS: number;
276
+ readonly NUMPAD_ENTER: number;
277
+ readonly NUMPAD_1: number;
278
+ readonly NUMPAD_2: number;
279
+ readonly NUMPAD_3: number;
280
+ readonly NUMPAD_4: number;
281
+ readonly NUMPAD_5: number;
282
+ readonly NUMPAD_6: number;
283
+ readonly NUMPAD_7: number;
284
+ readonly NUMPAD_8: number;
285
+ readonly NUMPAD_9: number;
286
+ readonly NUMPAD_0: number;
287
+ readonly NUMPAD_PERIOD: number;
288
+ };
289
+
290
+ // Keyboard modifiers
291
+ export const MOD: {
292
+ readonly CTRL: number;
293
+ readonly SHIFT: number;
294
+ readonly ALT: number;
295
+ readonly WIN: number;
296
+ };
297
+
298
+ // Mouse buttons
299
+ export const MOUSE_BTN: {
300
+ readonly LEFT: number;
301
+ readonly RIGHT: number;
302
+ readonly MIDDLE: number;
303
+ };
304
+
305
+ // Command codes
306
+ export const CMD: {
307
+ readonly PING: number;
308
+ readonly GET_VERSION: number;
309
+ readonly BOOTLOADER: number;
310
+ readonly KEY_PRESS: number;
311
+ readonly KEY_RELEASE: number;
312
+ readonly KEY_TAP: number;
313
+ readonly KEY_MODIFIER: number;
314
+ readonly KEY_RELEASE_ALL: number;
315
+ readonly KEY_TYPE_STRING: number;
316
+ readonly MOUSE_MOVE: number;
317
+ readonly MOUSE_CLICK: number;
318
+ readonly MOUSE_PRESS: number;
319
+ readonly MOUSE_RELEASE: number;
320
+ readonly MOUSE_SCROLL: number;
321
+ readonly DELAY: number;
322
+ };
323
+
324
+ // Status codes
325
+ export const STATUS: {
326
+ readonly OK: number;
327
+ readonly ERROR_UNKNOWN: number;
328
+ readonly ERROR_INVALID: number;
329
+ readonly ERROR_OVERFLOW: number;
330
+ };
331
+
332
+ // Device config
333
+ export const VID: number;
334
+ export const PID: number;
335
+ export const VENDOR_USAGE_PAGE: number;
336
+ export const DEFAULT_TIMEOUT: number;
337
+ export const TYPE_STRING_TIMEOUT: number;
338
+