@adhdev/daemon-core 0.5.28 → 0.5.30
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.
- package/dist/index.js +89 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/commands/cdp-commands.ts +60 -12
package/package.json
CHANGED
|
@@ -8,6 +8,17 @@ import * as fs from 'fs';
|
|
|
8
8
|
import * as path from 'path';
|
|
9
9
|
import * as os from 'os';
|
|
10
10
|
|
|
11
|
+
// Windows Virtual Key Code mapping for special keys (Chrome CDP requirement)
|
|
12
|
+
const KEY_TO_VK: Record<string, number> = {
|
|
13
|
+
Backspace: 8, Tab: 9, Enter: 13, Escape: 27, Space: 32,
|
|
14
|
+
ArrowLeft: 37, ArrowUp: 38, ArrowRight: 39, ArrowDown: 40,
|
|
15
|
+
Delete: 46, Home: 36, End: 35, PageUp: 33, PageDown: 34,
|
|
16
|
+
Insert: 45, F1: 112, F2: 113, F3: 114, F4: 115, F5: 116,
|
|
17
|
+
F6: 117, F7: 118, F8: 119, F9: 120, F10: 121, F11: 122, F12: 123,
|
|
18
|
+
Control: 17, Shift: 16, Alt: 18, Meta: 91, CapsLock: 20,
|
|
19
|
+
' ': 32,
|
|
20
|
+
};
|
|
21
|
+
|
|
11
22
|
// ─── CDP direct commands ──────────────────────────
|
|
12
23
|
|
|
13
24
|
export async function handleCdpEval(h: CommandHelpers, args: any): Promise<CommandResult> {
|
|
@@ -76,17 +87,38 @@ export async function handleCdpRemoteAction(h: CommandHelpers, args: any): Promi
|
|
|
76
87
|
try {
|
|
77
88
|
switch (action) {
|
|
78
89
|
case 'input_key': {
|
|
79
|
-
const { key, modifiers } = params;
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
90
|
+
const { type: evType, key, code, text, unmodifiedText, modifiers } = params;
|
|
91
|
+
// modifiers is a numeric bitmask: 1=alt, 2=ctrl, 4=meta, 8=shift
|
|
92
|
+
const mod = typeof modifiers === 'number' ? modifiers : 0;
|
|
93
|
+
// Chrome CDP needs windowsVirtualKeyCode for special keys to register
|
|
94
|
+
const vk = KEY_TO_VK[key] || (key.length === 1 ? key.charCodeAt(0) : 0);
|
|
95
|
+
if (evType === 'char') {
|
|
96
|
+
// Character input — single char event with text field
|
|
97
|
+
await h.getCdp()!.send('Input.dispatchKeyEvent', {
|
|
98
|
+
type: 'char', key, code,
|
|
99
|
+
text: text || key,
|
|
100
|
+
unmodifiedText: unmodifiedText || text || key,
|
|
101
|
+
...(vk ? { windowsVirtualKeyCode: vk, nativeVirtualKeyCode: vk } : {}),
|
|
102
|
+
...(mod ? { modifiers: mod } : {}),
|
|
103
|
+
});
|
|
104
|
+
} else {
|
|
105
|
+
// Non-character key (arrows, Enter, Escape, Tab, Backspace, etc.)
|
|
106
|
+
await h.getCdp()!.send('Input.dispatchKeyEvent', {
|
|
107
|
+
type: 'rawKeyDown', key, code,
|
|
108
|
+
...(text ? { text } : {}),
|
|
109
|
+
...(vk ? { windowsVirtualKeyCode: vk, nativeVirtualKeyCode: vk } : {}),
|
|
110
|
+
...(mod ? { modifiers: mod } : {}),
|
|
111
|
+
});
|
|
112
|
+
await h.getCdp()!.send('Input.dispatchKeyEvent', {
|
|
113
|
+
type: 'keyUp', key, code,
|
|
114
|
+
...(vk ? { windowsVirtualKeyCode: vk, nativeVirtualKeyCode: vk } : {}),
|
|
115
|
+
...(mod ? { modifiers: mod } : {}),
|
|
116
|
+
});
|
|
117
|
+
}
|
|
86
118
|
return { success: true };
|
|
87
119
|
}
|
|
88
120
|
case 'input_click': {
|
|
89
|
-
let { x, y, nx, ny, button: btn } = params;
|
|
121
|
+
let { x, y, nx, ny, button: btn, clickCount } = params;
|
|
90
122
|
if ((x === undefined || y === undefined) && nx !== undefined && ny !== undefined) {
|
|
91
123
|
const viewport = await h.getCdp()!.evaluate(
|
|
92
124
|
'JSON.stringify({ w: window.innerWidth, h: window.innerHeight })'
|
|
@@ -98,11 +130,12 @@ export async function handleCdpRemoteAction(h: CommandHelpers, args: any): Promi
|
|
|
98
130
|
if (x === undefined || y === undefined) {
|
|
99
131
|
return { success: false, error: 'No coordinates provided (x,y or nx,ny required)' };
|
|
100
132
|
}
|
|
133
|
+
const cc = clickCount || 1;
|
|
101
134
|
await h.getCdp()!.send('Input.dispatchMouseEvent', {
|
|
102
|
-
type: 'mousePressed', x, y, button: btn || 'left', clickCount:
|
|
135
|
+
type: 'mousePressed', x, y, button: btn || 'left', clickCount: cc,
|
|
103
136
|
});
|
|
104
137
|
await h.getCdp()!.send('Input.dispatchMouseEvent', {
|
|
105
|
-
type: 'mouseReleased', x, y, button: btn || 'left', clickCount:
|
|
138
|
+
type: 'mouseReleased', x, y, button: btn || 'left', clickCount: cc,
|
|
106
139
|
});
|
|
107
140
|
return { success: true, x, y };
|
|
108
141
|
}
|
|
@@ -110,9 +143,9 @@ export async function handleCdpRemoteAction(h: CommandHelpers, args: any): Promi
|
|
|
110
143
|
const { text } = params;
|
|
111
144
|
for (const char of text || '') {
|
|
112
145
|
await h.getCdp()!.send('Input.dispatchKeyEvent', {
|
|
113
|
-
type: '
|
|
146
|
+
type: 'char', text: char, key: char,
|
|
147
|
+
unmodifiedText: char,
|
|
114
148
|
});
|
|
115
|
-
await h.getCdp()!.send('Input.dispatchKeyEvent', { type: 'keyUp', key: char });
|
|
116
149
|
}
|
|
117
150
|
return { success: true };
|
|
118
151
|
}
|
|
@@ -138,6 +171,21 @@ export async function handleCdpRemoteAction(h: CommandHelpers, args: any): Promi
|
|
|
138
171
|
});
|
|
139
172
|
return { success: true };
|
|
140
173
|
}
|
|
174
|
+
case 'input_mouseMoved': {
|
|
175
|
+
let { x, y, nx, ny } = params;
|
|
176
|
+
if ((x === undefined || y === undefined) && nx !== undefined && ny !== undefined) {
|
|
177
|
+
const viewport = await h.getCdp()!.evaluate(
|
|
178
|
+
'JSON.stringify({ w: window.innerWidth, h: window.innerHeight })'
|
|
179
|
+
) as string;
|
|
180
|
+
const { w, h: vh } = JSON.parse(viewport);
|
|
181
|
+
x = Math.round(nx * w);
|
|
182
|
+
y = Math.round(ny * vh);
|
|
183
|
+
}
|
|
184
|
+
await h.getCdp()!.send('Input.dispatchMouseEvent', {
|
|
185
|
+
type: 'mouseMoved', x: x || 0, y: y || 0,
|
|
186
|
+
});
|
|
187
|
+
return { success: true };
|
|
188
|
+
}
|
|
141
189
|
default:
|
|
142
190
|
return { success: false, error: `Unknown remote action: ${action}` };
|
|
143
191
|
}
|