@copylee/dsh-computer-use 0.10.0 → 0.12.0
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/README.md +31 -9
- package/helper/CuHelper.cs +848 -76
- package/lib/client.js +360 -100
- package/lib/index.js +860 -59
- package/lib/types/access.d.ts +2 -0
- package/lib/types/cdp.d.ts +55 -0
- package/lib/types/client/index.d.ts +4 -0
- package/lib/types/client/select.d.ts +1 -1
- package/lib/types/client/window-refs.d.ts +37 -0
- package/lib/types/computer.d.ts +32 -2
- package/lib/types/diagnostics.d.ts +7 -0
- package/lib/types/helper-client.d.ts +1 -0
- package/lib/types/index.d.ts +12 -3
- package/lib/types/macros.d.ts +30 -0
- package/lib/types/overlay.d.ts +26 -2
- package/lib/types/routes.d.ts +8 -1
- package/lib/types/target.d.ts +4 -0
- package/lib/types/tools.d.ts +3 -0
- package/lib/types/update-check.d.ts +15 -0
- package/package.json +1 -1
package/helper/CuHelper.cs
CHANGED
|
@@ -28,6 +28,7 @@ using System.Threading;
|
|
|
28
28
|
using System.Web.Script.Serialization;
|
|
29
29
|
using System.Windows.Automation;
|
|
30
30
|
using System.Windows.Forms;
|
|
31
|
+
using Microsoft.Win32;
|
|
31
32
|
|
|
32
33
|
namespace DshComputerUse
|
|
33
34
|
{
|
|
@@ -122,13 +123,20 @@ namespace DshComputerUse
|
|
|
122
123
|
[DllImport("user32.dll")] public static extern bool SetWindowDisplayAffinity(IntPtr hwnd, uint affinity);
|
|
123
124
|
[DllImport("user32.dll")] public static extern bool ReleaseCapture();
|
|
124
125
|
[DllImport("user32.dll")] public static extern IntPtr SendMessage(IntPtr hwnd, uint msg, IntPtr w, IntPtr l);
|
|
126
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
127
|
+
public struct GUITHREADINFO { public int cbSize; public int flags; public IntPtr hwndActive; public IntPtr hwndFocus; public IntPtr hwndCapture; public IntPtr hwndMenuOwner; public IntPtr hwndMoveSize; public IntPtr hwndCaret; public RECT rcCaret; }
|
|
128
|
+
[DllImport("user32.dll")] public static extern bool GetGUIThreadInfo(uint idThread, ref GUITHREADINFO lpgui);
|
|
125
129
|
|
|
126
130
|
public delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);
|
|
131
|
+
public delegate IntPtr LowLevelMouseProc(int nCode, IntPtr wParam, IntPtr lParam);
|
|
127
132
|
[DllImport("user32.dll", SetLastError = true)] public static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc fn, IntPtr hMod, uint threadId);
|
|
133
|
+
[DllImport("user32.dll", SetLastError = true)] public static extern IntPtr SetWindowsHookEx(int idHook, LowLevelMouseProc fn, IntPtr hMod, uint threadId);
|
|
128
134
|
[DllImport("user32.dll")] public static extern bool UnhookWindowsHookEx(IntPtr hook);
|
|
129
135
|
[DllImport("user32.dll")] public static extern IntPtr CallNextHookEx(IntPtr hook, int nCode, IntPtr wParam, IntPtr lParam);
|
|
130
136
|
[StructLayout(LayoutKind.Sequential)]
|
|
131
137
|
public struct KBDLLHOOKSTRUCT { public uint vkCode; public uint scanCode; public uint flags; public uint time; public IntPtr dwExtraInfo; }
|
|
138
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
139
|
+
public struct MSLLHOOKSTRUCT { public POINT pt; public uint mouseData; public uint flags; public uint time; public IntPtr dwExtraInfo; }
|
|
132
140
|
|
|
133
141
|
public const uint INPUT_MOUSE = 0, INPUT_KEYBOARD = 1;
|
|
134
142
|
public const uint KEYEVENTF_EXTENDEDKEY = 0x1, KEYEVENTF_KEYUP = 0x2, KEYEVENTF_UNICODE = 0x4;
|
|
@@ -265,6 +273,17 @@ namespace DshComputerUse
|
|
|
265
273
|
try { Emit(e); } catch (Exception) { }
|
|
266
274
|
});
|
|
267
275
|
}
|
|
276
|
+
|
|
277
|
+
public static void EmitDataEvent(string name, Dictionary<string, object> data)
|
|
278
|
+
{
|
|
279
|
+
ThreadPool.QueueUserWorkItem(delegate
|
|
280
|
+
{
|
|
281
|
+
var e = new Dictionary<string, object>();
|
|
282
|
+
e["event"] = name;
|
|
283
|
+
e["data"] = data;
|
|
284
|
+
try { Emit(e); } catch (Exception) { }
|
|
285
|
+
});
|
|
286
|
+
}
|
|
268
287
|
}
|
|
269
288
|
|
|
270
289
|
internal static class Commands
|
|
@@ -329,6 +348,9 @@ namespace DshComputerUse
|
|
|
329
348
|
case "ui": return Uia.Elements(r);
|
|
330
349
|
case "text": return Uia.Text(r);
|
|
331
350
|
case "ocr": return Ocr.Read(r);
|
|
351
|
+
case "marks": return Uia.Marks(r);
|
|
352
|
+
case "password_focus": return Uia.PasswordFocus();
|
|
353
|
+
case "ui_point_click": return Uia.ClickAtPoint(r);
|
|
332
354
|
case "overlay_show": Overlay.ExcludeFromCapture = Args.Bool(r, "excludeFromCapture", true); Overlay.Show(r); return null;
|
|
333
355
|
case "overlay_pause": Overlay.SetPaused(Args.Bool(r, "paused", false)); return null;
|
|
334
356
|
case "window_card": CardLayer.SetOpacity(Args.Int(r, "opacity", 100)); return Windows.Card(new IntPtr(Convert.ToInt64(r["hwnd"])), Args.Int(r, "x", 0), Args.Int(r, "y", 0), Args.Int(r, "width", 0), Args.Int(r, "height", 0));
|
|
@@ -993,19 +1015,19 @@ namespace DshComputerUse
|
|
|
993
1015
|
public static object Click(Dictionary<string, object> r)
|
|
994
1016
|
{
|
|
995
1017
|
int x, y;
|
|
1018
|
+
Native.POINT savedCursor;
|
|
1019
|
+
bool hadSavedCursor = Native.GetCursorPos(out savedCursor);
|
|
1020
|
+
bool restorePointer = Args.Bool(r, "restorePointer", false);
|
|
996
1021
|
bool moved = Args.Has(r, "x");
|
|
997
1022
|
if (moved)
|
|
998
1023
|
{
|
|
999
1024
|
x = Args.Int(r, "x", 0);
|
|
1000
1025
|
y = Args.Int(r, "y", 0);
|
|
1001
|
-
Overlay.Dodge(x, y);
|
|
1002
|
-
Move(x, y);
|
|
1003
1026
|
}
|
|
1004
1027
|
else
|
|
1005
1028
|
{
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
else { x = pos.X; y = pos.Y; }
|
|
1029
|
+
if (!hadSavedCursor) { x = 0; y = 0; }
|
|
1030
|
+
else { x = savedCursor.X; y = savedCursor.Y; }
|
|
1009
1031
|
}
|
|
1010
1032
|
string button = Args.Str(r, "button", "left");
|
|
1011
1033
|
if (button != "right" && button != "middle") button = "left";
|
|
@@ -1019,8 +1041,16 @@ namespace DshComputerUse
|
|
|
1019
1041
|
if (showTarget)
|
|
1020
1042
|
{
|
|
1021
1043
|
string preVerb = count >= 3 ? "三击" : count == 2 ? "双击" : button == "right" ? "右键" : button == "middle" ? "中键" : "点击";
|
|
1022
|
-
Overlay.
|
|
1023
|
-
|
|
1044
|
+
Overlay.GlideMark(x, y, preVerb + " " + coordLabel, Color.FromArgb(217, 119, 87), 2000, false, false);
|
|
1045
|
+
}
|
|
1046
|
+
if (moved)
|
|
1047
|
+
{
|
|
1048
|
+
Overlay.Dodge(x, y);
|
|
1049
|
+
Move(x, y);
|
|
1050
|
+
}
|
|
1051
|
+
if (showTarget)
|
|
1052
|
+
{
|
|
1053
|
+
Thread.Sleep(70);
|
|
1024
1054
|
}
|
|
1025
1055
|
else if (moved)
|
|
1026
1056
|
{
|
|
@@ -1037,7 +1067,14 @@ namespace DshComputerUse
|
|
|
1037
1067
|
if (i < count - 1) Thread.Sleep(40);
|
|
1038
1068
|
}
|
|
1039
1069
|
}
|
|
1040
|
-
finally
|
|
1070
|
+
finally
|
|
1071
|
+
{
|
|
1072
|
+
Modifiers(mods, true);
|
|
1073
|
+
if (restorePointer && moved && hadSavedCursor)
|
|
1074
|
+
{
|
|
1075
|
+
try { Native.SetCursorPos(savedCursor.X, savedCursor.Y); } catch (Exception) { }
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1041
1078
|
if (showTarget)
|
|
1042
1079
|
{
|
|
1043
1080
|
Overlay.MarkResult(x, y, button, count, coordLabel);
|
|
@@ -1049,6 +1086,7 @@ namespace DshComputerUse
|
|
|
1049
1086
|
result["button"] = button;
|
|
1050
1087
|
result["count"] = count;
|
|
1051
1088
|
result["repeat"] = repeat;
|
|
1089
|
+
result["restoredPointer"] = restorePointer && moved && hadSavedCursor;
|
|
1052
1090
|
return result;
|
|
1053
1091
|
}
|
|
1054
1092
|
|
|
@@ -2210,10 +2248,120 @@ namespace DshComputerUse
|
|
|
2210
2248
|
lock (Gate) { return Load(); }
|
|
2211
2249
|
}
|
|
2212
2250
|
|
|
2251
|
+
static void AddIfNew(List<KeyValuePair<string, string>> list, HashSet<string> seen, string name, string id)
|
|
2252
|
+
{
|
|
2253
|
+
if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(id)) return;
|
|
2254
|
+
string key = name.Trim().ToLowerInvariant() + "\u0000" + id.Trim().ToLowerInvariant();
|
|
2255
|
+
if (seen.Add(key)) list.Add(new KeyValuePair<string, string>(name.Trim(), id.Trim()));
|
|
2256
|
+
}
|
|
2257
|
+
|
|
2258
|
+
static string ExtractExePath(string raw)
|
|
2259
|
+
{
|
|
2260
|
+
if (string.IsNullOrEmpty(raw)) return "";
|
|
2261
|
+
string s = raw.Trim();
|
|
2262
|
+
if (s.StartsWith("\""))
|
|
2263
|
+
{
|
|
2264
|
+
int end = s.IndexOf('"', 1);
|
|
2265
|
+
if (end > 1) s = s.Substring(1, end - 1);
|
|
2266
|
+
}
|
|
2267
|
+
else
|
|
2268
|
+
{
|
|
2269
|
+
int comma = s.IndexOf(',');
|
|
2270
|
+
if (comma > 0) s = s.Substring(0, comma);
|
|
2271
|
+
}
|
|
2272
|
+
s = s.Trim();
|
|
2273
|
+
if (!s.EndsWith(".exe", StringComparison.OrdinalIgnoreCase)) return "";
|
|
2274
|
+
return File.Exists(s) ? s : "";
|
|
2275
|
+
}
|
|
2276
|
+
|
|
2277
|
+
static void ScanStartFolder(string dir, int depth, List<KeyValuePair<string, string>> list, HashSet<string> seen)
|
|
2278
|
+
{
|
|
2279
|
+
if (depth > 3 || string.IsNullOrEmpty(dir) || !Directory.Exists(dir)) return;
|
|
2280
|
+
try
|
|
2281
|
+
{
|
|
2282
|
+
foreach (var f in Directory.GetFiles(dir, "*.lnk"))
|
|
2283
|
+
{
|
|
2284
|
+
string name = Path.GetFileNameWithoutExtension(f);
|
|
2285
|
+
if (name.IndexOf("uninstall", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("卸载", StringComparison.OrdinalIgnoreCase) >= 0) continue;
|
|
2286
|
+
AddIfNew(list, seen, name, "lnk:" + f);
|
|
2287
|
+
}
|
|
2288
|
+
foreach (var sub in Directory.GetDirectories(dir))
|
|
2289
|
+
ScanStartFolder(sub, depth + 1, list, seen);
|
|
2290
|
+
}
|
|
2291
|
+
catch (Exception) { }
|
|
2292
|
+
}
|
|
2293
|
+
|
|
2294
|
+
static void ScanRegistryApps(List<KeyValuePair<string, string>> list, HashSet<string> seen)
|
|
2295
|
+
{
|
|
2296
|
+
var roots = new RegistryKey[] { Registry.CurrentUser, Registry.LocalMachine };
|
|
2297
|
+
foreach (var root in roots)
|
|
2298
|
+
{
|
|
2299
|
+
// 1. App Paths (e.g. WeChat.exe, chrome.exe, code.exe)
|
|
2300
|
+
try
|
|
2301
|
+
{
|
|
2302
|
+
using (var ap = root.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths"))
|
|
2303
|
+
{
|
|
2304
|
+
if (ap != null)
|
|
2305
|
+
{
|
|
2306
|
+
foreach (var subName in ap.GetSubKeyNames())
|
|
2307
|
+
{
|
|
2308
|
+
try
|
|
2309
|
+
{
|
|
2310
|
+
using (var sub = ap.OpenSubKey(subName))
|
|
2311
|
+
{
|
|
2312
|
+
if (sub == null) continue;
|
|
2313
|
+
string exe = ExtractExePath(Convert.ToString(sub.GetValue(null)) ?? "");
|
|
2314
|
+
if (exe.Length > 0) AddIfNew(list, seen, Path.GetFileNameWithoutExtension(subName), "exe:" + exe);
|
|
2315
|
+
}
|
|
2316
|
+
}
|
|
2317
|
+
catch (Exception) { }
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2320
|
+
}
|
|
2321
|
+
}
|
|
2322
|
+
catch (Exception) { }
|
|
2323
|
+
|
|
2324
|
+
// 2. Uninstall table DisplayName + DisplayIcon (.exe)
|
|
2325
|
+
var uninstallPaths = new string[] {
|
|
2326
|
+
@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall",
|
|
2327
|
+
@"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall",
|
|
2328
|
+
};
|
|
2329
|
+
foreach (var upath in uninstallPaths)
|
|
2330
|
+
{
|
|
2331
|
+
try
|
|
2332
|
+
{
|
|
2333
|
+
using (var uk = root.OpenSubKey(upath))
|
|
2334
|
+
{
|
|
2335
|
+
if (uk == null) continue;
|
|
2336
|
+
foreach (var subName in uk.GetSubKeyNames())
|
|
2337
|
+
{
|
|
2338
|
+
try
|
|
2339
|
+
{
|
|
2340
|
+
using (var sub = uk.OpenSubKey(subName))
|
|
2341
|
+
{
|
|
2342
|
+
if (sub == null) continue;
|
|
2343
|
+
string displayName = Convert.ToString(sub.GetValue("DisplayName")) ?? "";
|
|
2344
|
+
if (displayName.Length == 0) continue;
|
|
2345
|
+
string iconExe = ExtractExePath(Convert.ToString(sub.GetValue("DisplayIcon")) ?? "");
|
|
2346
|
+
if (iconExe.Length == 0) continue;
|
|
2347
|
+
if (iconExe.IndexOf("unins", StringComparison.OrdinalIgnoreCase) >= 0 || iconExe.IndexOf("setup", StringComparison.OrdinalIgnoreCase) >= 0) continue;
|
|
2348
|
+
AddIfNew(list, seen, displayName, "exe:" + iconExe);
|
|
2349
|
+
}
|
|
2350
|
+
}
|
|
2351
|
+
catch (Exception) { }
|
|
2352
|
+
}
|
|
2353
|
+
}
|
|
2354
|
+
}
|
|
2355
|
+
catch (Exception) { }
|
|
2356
|
+
}
|
|
2357
|
+
}
|
|
2358
|
+
}
|
|
2359
|
+
|
|
2213
2360
|
static List<KeyValuePair<string, string>> Load()
|
|
2214
2361
|
{
|
|
2215
2362
|
if (cache != null && (DateTime.UtcNow - cachedAt).TotalSeconds < 600) return cache;
|
|
2216
2363
|
var list = new List<KeyValuePair<string, string>>();
|
|
2364
|
+
var seen = new HashSet<string>();
|
|
2217
2365
|
Type t = Type.GetTypeFromProgID("Shell.Application");
|
|
2218
2366
|
dynamic shell = Activator.CreateInstance(t);
|
|
2219
2367
|
try
|
|
@@ -2222,21 +2370,22 @@ namespace DshComputerUse
|
|
|
2222
2370
|
foreach (dynamic item in folder.Items())
|
|
2223
2371
|
{
|
|
2224
2372
|
string name = item.Name; string path = item.Path;
|
|
2225
|
-
|
|
2373
|
+
AddIfNew(list, seen, name, path);
|
|
2226
2374
|
}
|
|
2227
2375
|
}
|
|
2228
2376
|
finally { Marshal.FinalReleaseComObject(shell); }
|
|
2229
|
-
// Desktop shortcuts
|
|
2230
|
-
foreach (var folder in new[] {
|
|
2377
|
+
// Desktop & Start Menu shortcuts: portable and classic apps often only live there.
|
|
2378
|
+
foreach (var folder in new[] {
|
|
2379
|
+
Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),
|
|
2380
|
+
Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory),
|
|
2381
|
+
Environment.GetFolderPath(Environment.SpecialFolder.Programs),
|
|
2382
|
+
Environment.GetFolderPath(Environment.SpecialFolder.CommonPrograms),
|
|
2383
|
+
})
|
|
2231
2384
|
{
|
|
2232
|
-
|
|
2233
|
-
{
|
|
2234
|
-
if (folder.Length == 0 || !Directory.Exists(folder)) continue;
|
|
2235
|
-
foreach (var f in Directory.GetFiles(folder, "*.lnk"))
|
|
2236
|
-
list.Add(new KeyValuePair<string, string>(Path.GetFileNameWithoutExtension(f), "lnk:" + f));
|
|
2237
|
-
}
|
|
2238
|
-
catch (Exception) { }
|
|
2385
|
+
ScanStartFolder(folder, 0, list, seen);
|
|
2239
2386
|
}
|
|
2387
|
+
// Registry App Paths & Uninstall executable locations.
|
|
2388
|
+
ScanRegistryApps(list, seen);
|
|
2240
2389
|
cache = list; cachedAt = DateTime.UtcNow;
|
|
2241
2390
|
return list;
|
|
2242
2391
|
}
|
|
@@ -2270,6 +2419,7 @@ namespace DshComputerUse
|
|
|
2270
2419
|
string args = Args.Str(r, "args", "");
|
|
2271
2420
|
ProcessStartInfo psi;
|
|
2272
2421
|
if (appId.StartsWith("lnk:")) psi = new ProcessStartInfo(appId.Substring(4));
|
|
2422
|
+
else if (appId.StartsWith("exe:")) psi = new ProcessStartInfo(appId.Substring(4));
|
|
2273
2423
|
else if (appId.Length > 0) psi = new ProcessStartInfo("explorer.exe", "shell:AppsFolder\\" + appId);
|
|
2274
2424
|
else { psi = new ProcessStartInfo(target); if (args.Length > 0) psi.Arguments = args; }
|
|
2275
2425
|
psi.UseShellExecute = true;
|
|
@@ -2723,6 +2873,7 @@ namespace DshComputerUse
|
|
|
2723
2873
|
if (++looked > 200) break;
|
|
2724
2874
|
try
|
|
2725
2875
|
{
|
|
2876
|
+
if (IsPasswordElement(el)) continue;
|
|
2726
2877
|
object pattern;
|
|
2727
2878
|
if (!el.TryGetCurrentPattern(ValuePattern.Pattern, out pattern)) continue;
|
|
2728
2879
|
string got = ((ValuePattern)pattern).Current.Value;
|
|
@@ -2753,6 +2904,305 @@ namespace DshComputerUse
|
|
|
2753
2904
|
return sb.ToString();
|
|
2754
2905
|
}
|
|
2755
2906
|
|
|
2907
|
+
static bool IsWin32PasswordHwnd(IntPtr h)
|
|
2908
|
+
{
|
|
2909
|
+
if (h == IntPtr.Zero || !Native.IsWindow(h)) return false;
|
|
2910
|
+
var cls = new StringBuilder(64);
|
|
2911
|
+
Native.GetClassName(h, cls, cls.Capacity);
|
|
2912
|
+
string c = cls.ToString();
|
|
2913
|
+
if (c.IndexOf("Edit", StringComparison.OrdinalIgnoreCase) < 0 && c.IndexOf("RichEdit", StringComparison.OrdinalIgnoreCase) < 0)
|
|
2914
|
+
return false;
|
|
2915
|
+
int style = Native.GetWindowLong(h, -16); // GWL_STYLE
|
|
2916
|
+
return (style & 0x0020) != 0; // ES_PASSWORD
|
|
2917
|
+
}
|
|
2918
|
+
|
|
2919
|
+
static bool IsPasswordElement(AutomationElement el)
|
|
2920
|
+
{
|
|
2921
|
+
if (el == null) return false;
|
|
2922
|
+
try
|
|
2923
|
+
{
|
|
2924
|
+
if (el.Current.IsPassword) return true;
|
|
2925
|
+
int nh = el.Current.NativeWindowHandle;
|
|
2926
|
+
if (nh != 0 && IsWin32PasswordHwnd(new IntPtr(nh))) return true;
|
|
2927
|
+
}
|
|
2928
|
+
catch (Exception) { }
|
|
2929
|
+
return false;
|
|
2930
|
+
}
|
|
2931
|
+
|
|
2932
|
+
/** Check whether keyboard focus is currently inside a password input (UIA IsPassword or Win32 ES_PASSWORD). */
|
|
2933
|
+
public static object PasswordFocus()
|
|
2934
|
+
{
|
|
2935
|
+
bool isPwd = false;
|
|
2936
|
+
string reason = "";
|
|
2937
|
+
string name = "";
|
|
2938
|
+
try
|
|
2939
|
+
{
|
|
2940
|
+
IntPtr fg = Native.GetForegroundWindow();
|
|
2941
|
+
if (fg != IntPtr.Zero)
|
|
2942
|
+
{
|
|
2943
|
+
uint pid;
|
|
2944
|
+
uint tid = Native.GetWindowThreadProcessId(fg, out pid);
|
|
2945
|
+
var gti = new Native.GUITHREADINFO();
|
|
2946
|
+
gti.cbSize = Marshal.SizeOf(typeof(Native.GUITHREADINFO));
|
|
2947
|
+
if (Native.GetGUIThreadInfo(tid, ref gti) && gti.hwndFocus != IntPtr.Zero && IsWin32PasswordHwnd(gti.hwndFocus))
|
|
2948
|
+
{
|
|
2949
|
+
isPwd = true;
|
|
2950
|
+
reason = "win32_es_password";
|
|
2951
|
+
}
|
|
2952
|
+
}
|
|
2953
|
+
}
|
|
2954
|
+
catch (Exception) { }
|
|
2955
|
+
if (!isPwd)
|
|
2956
|
+
{
|
|
2957
|
+
var worker = new Thread(delegate ()
|
|
2958
|
+
{
|
|
2959
|
+
try
|
|
2960
|
+
{
|
|
2961
|
+
var focused = AutomationElement.FocusedElement;
|
|
2962
|
+
if (focused != null && IsPasswordElement(focused))
|
|
2963
|
+
{
|
|
2964
|
+
isPwd = true;
|
|
2965
|
+
reason = "uia_is_password";
|
|
2966
|
+
name = focused.Current.Name ?? "";
|
|
2967
|
+
}
|
|
2968
|
+
}
|
|
2969
|
+
catch (Exception) { }
|
|
2970
|
+
});
|
|
2971
|
+
worker.IsBackground = true;
|
|
2972
|
+
worker.SetApartmentState(ApartmentState.MTA);
|
|
2973
|
+
worker.Start();
|
|
2974
|
+
worker.Join(500);
|
|
2975
|
+
}
|
|
2976
|
+
var d = new Dictionary<string, object>();
|
|
2977
|
+
d["password"] = isPwd;
|
|
2978
|
+
d["reason"] = reason;
|
|
2979
|
+
d["name"] = name;
|
|
2980
|
+
return d;
|
|
2981
|
+
}
|
|
2982
|
+
|
|
2983
|
+
/** Lightweight bounded lookup of the UIA control at physical point (x, y) for user-takeover feedback. */
|
|
2984
|
+
public static void DescribeAtPoint(int x, int y, out string role, out string name, out bool isPassword)
|
|
2985
|
+
{
|
|
2986
|
+
string r = "", n = "";
|
|
2987
|
+
bool pwd = false;
|
|
2988
|
+
var worker = new Thread(delegate ()
|
|
2989
|
+
{
|
|
2990
|
+
try
|
|
2991
|
+
{
|
|
2992
|
+
var el = AutomationElement.FromPoint(new System.Windows.Point(x, y));
|
|
2993
|
+
if (el == null) return;
|
|
2994
|
+
pwd = IsPasswordElement(el);
|
|
2995
|
+
var ct = el.Current.ControlType;
|
|
2996
|
+
r = pwd ? "PasswordField" : (ct != null ? ct.ProgrammaticName.Replace("ControlType.", "") : "");
|
|
2997
|
+
string raw = pwd ? "" : (el.Current.Name ?? "").Trim();
|
|
2998
|
+
n = raw.Length > 60 ? raw.Substring(0, 60) + "…" : raw;
|
|
2999
|
+
}
|
|
3000
|
+
catch (Exception) { }
|
|
3001
|
+
});
|
|
3002
|
+
worker.IsBackground = true;
|
|
3003
|
+
worker.SetApartmentState(ApartmentState.MTA);
|
|
3004
|
+
worker.Start();
|
|
3005
|
+
worker.Join(260);
|
|
3006
|
+
role = r; name = n; isPassword = pwd;
|
|
3007
|
+
}
|
|
3008
|
+
|
|
3009
|
+
/** Lightweight bounded lookup of the focused UIA control for privacy-safe typing feedback. */
|
|
3010
|
+
public static void DescribeFocused(out string role, out string name, out bool isPassword)
|
|
3011
|
+
{
|
|
3012
|
+
string r = "", n = "";
|
|
3013
|
+
bool pwd = false;
|
|
3014
|
+
var worker = new Thread(delegate ()
|
|
3015
|
+
{
|
|
3016
|
+
try
|
|
3017
|
+
{
|
|
3018
|
+
var el = AutomationElement.FocusedElement;
|
|
3019
|
+
if (el == null) return;
|
|
3020
|
+
pwd = IsPasswordElement(el);
|
|
3021
|
+
var ct = el.Current.ControlType;
|
|
3022
|
+
r = pwd ? "PasswordField" : (ct != null ? ct.ProgrammaticName.Replace("ControlType.", "") : "");
|
|
3023
|
+
string raw = pwd ? "" : (el.Current.Name ?? "").Trim();
|
|
3024
|
+
n = raw.Length > 60 ? raw.Substring(0, 60) + "…" : raw;
|
|
3025
|
+
}
|
|
3026
|
+
catch (Exception) { }
|
|
3027
|
+
});
|
|
3028
|
+
worker.IsBackground = true;
|
|
3029
|
+
worker.SetApartmentState(ApartmentState.MTA);
|
|
3030
|
+
worker.Start();
|
|
3031
|
+
worker.Join(240);
|
|
3032
|
+
role = r; name = n; isPassword = pwd;
|
|
3033
|
+
}
|
|
3034
|
+
|
|
3035
|
+
/**
|
|
3036
|
+
* Try to invoke/toggle/select an enabled native UIA control directly under
|
|
3037
|
+
* physical point (x, y) without moving the physical cursor or stealing focus.
|
|
3038
|
+
*/
|
|
3039
|
+
public static object ClickAtPoint(Dictionary<string, object> r)
|
|
3040
|
+
{
|
|
3041
|
+
int x = Args.Int(r, "x", 0);
|
|
3042
|
+
int y = Args.Int(r, "y", 0);
|
|
3043
|
+
long expectedHwnd = Args.Has(r, "hwnd") ? Convert.ToInt64(r["hwnd"]) : 0;
|
|
3044
|
+
bool ok = false;
|
|
3045
|
+
string mechanism = "";
|
|
3046
|
+
string role = "";
|
|
3047
|
+
string name = "";
|
|
3048
|
+
var worker = new Thread(delegate ()
|
|
3049
|
+
{
|
|
3050
|
+
try
|
|
3051
|
+
{
|
|
3052
|
+
var el = AutomationElement.FromPoint(new System.Windows.Point(x, y));
|
|
3053
|
+
if (el == null) return;
|
|
3054
|
+
if (!el.Current.IsEnabled || IsPasswordElement(el)) return;
|
|
3055
|
+
var ct = el.Current.ControlType;
|
|
3056
|
+
// Only intercept clearly semantic, single-click invocable controls;
|
|
3057
|
+
// never intercept Edit/Document/Pane/Custom/Group where cursor placement matters.
|
|
3058
|
+
bool allowed = ct == ControlType.Button || ct == ControlType.CheckBox || ct == ControlType.RadioButton
|
|
3059
|
+
|| ct == ControlType.MenuItem || ct == ControlType.TabItem || ct == ControlType.Hyperlink;
|
|
3060
|
+
if (!allowed) return;
|
|
3061
|
+
if (expectedHwnd != 0)
|
|
3062
|
+
{
|
|
3063
|
+
int nh = el.Current.NativeWindowHandle;
|
|
3064
|
+
IntPtr root = nh != 0 ? Native.GetAncestor(new IntPtr(nh), 2) : IntPtr.Zero;
|
|
3065
|
+
if (root != IntPtr.Zero && root.ToInt64() != expectedHwnd) return;
|
|
3066
|
+
}
|
|
3067
|
+
role = ct.ProgrammaticName.Replace("ControlType.", "");
|
|
3068
|
+
name = el.Current.Name ?? "";
|
|
3069
|
+
object pat;
|
|
3070
|
+
if (el.TryGetCurrentPattern(InvokePattern.Pattern, out pat))
|
|
3071
|
+
{
|
|
3072
|
+
((InvokePattern)pat).Invoke();
|
|
3073
|
+
ok = true;
|
|
3074
|
+
mechanism = "invoke";
|
|
3075
|
+
return;
|
|
3076
|
+
}
|
|
3077
|
+
if (el.TryGetCurrentPattern(TogglePattern.Pattern, out pat))
|
|
3078
|
+
{
|
|
3079
|
+
((TogglePattern)pat).Toggle();
|
|
3080
|
+
ok = true;
|
|
3081
|
+
mechanism = "toggle";
|
|
3082
|
+
return;
|
|
3083
|
+
}
|
|
3084
|
+
if (el.TryGetCurrentPattern(SelectionItemPattern.Pattern, out pat))
|
|
3085
|
+
{
|
|
3086
|
+
((SelectionItemPattern)pat).Select();
|
|
3087
|
+
ok = true;
|
|
3088
|
+
mechanism = "select";
|
|
3089
|
+
return;
|
|
3090
|
+
}
|
|
3091
|
+
}
|
|
3092
|
+
catch (Exception) { }
|
|
3093
|
+
});
|
|
3094
|
+
worker.IsBackground = true;
|
|
3095
|
+
worker.SetApartmentState(ApartmentState.MTA);
|
|
3096
|
+
worker.Start();
|
|
3097
|
+
worker.Join(900);
|
|
3098
|
+
var d = new Dictionary<string, object>();
|
|
3099
|
+
d["ok"] = ok;
|
|
3100
|
+
d["mechanism"] = mechanism;
|
|
3101
|
+
d["role"] = role;
|
|
3102
|
+
d["name"] = name;
|
|
3103
|
+
return d;
|
|
3104
|
+
}
|
|
3105
|
+
|
|
3106
|
+
/**
|
|
3107
|
+
* Set-of-Marks annotated screenshot: capture the display, draw crisp numbered
|
|
3108
|
+
* badges [1..N] over interactive UIA controls of the target window, and return
|
|
3109
|
+
* both the JPEG image and the indexed element list.
|
|
3110
|
+
*/
|
|
3111
|
+
public static object Marks(Dictionary<string, object> r)
|
|
3112
|
+
{
|
|
3113
|
+
int sx = Args.Int(r, "x", 0), sy = Args.Int(r, "y", 0);
|
|
3114
|
+
int sw = Args.Int(r, "width", 0), sh = Args.Int(r, "height", 0);
|
|
3115
|
+
int outW = Args.Int(r, "outWidth", sw), outH = Args.Int(r, "outHeight", sh);
|
|
3116
|
+
int quality = Math.Max(30, Math.Min(100, Args.Int(r, "quality", 75)));
|
|
3117
|
+
if (sw <= 0 || sh <= 0) throw new Exception("marks needs display width and height");
|
|
3118
|
+
var ui = Elements(r) as Dictionary<string, object>;
|
|
3119
|
+
var rawElements = ui != null && ui.ContainsKey("elements") ? ui["elements"] as List<object> : new List<object>();
|
|
3120
|
+
if (rawElements == null) rawElements = new List<object>();
|
|
3121
|
+
|
|
3122
|
+
string via;
|
|
3123
|
+
using (var rawBmp = Screen2.Grab(sx, sy, sw, sh, out via))
|
|
3124
|
+
using (var canvas = new Bitmap(outW, outH, PixelFormat.Format24bppRgb))
|
|
3125
|
+
using (var g = Graphics.FromImage(canvas))
|
|
3126
|
+
{
|
|
3127
|
+
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
|
3128
|
+
g.SmoothingMode = SmoothingMode.AntiAlias;
|
|
3129
|
+
g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
|
|
3130
|
+
g.DrawImage(rawBmp, 0, 0, outW, outH);
|
|
3131
|
+
|
|
3132
|
+
double scaleX = (double)outW / sw;
|
|
3133
|
+
double scaleY = (double)outH / sh;
|
|
3134
|
+
var placed = new List<RectangleF>();
|
|
3135
|
+
using (var font = new Font("Microsoft YaHei UI", 10.5f, FontStyle.Bold, GraphicsUnit.Pixel))
|
|
3136
|
+
using (var fmt = new StringFormat(StringFormat.GenericTypographic))
|
|
3137
|
+
using (var bgBrush = new SolidBrush(Color.FromArgb(228, 217, 119, 87)))
|
|
3138
|
+
using (var borderPen = new Pen(Color.FromArgb(245, 255, 255, 255), 1.3f))
|
|
3139
|
+
using (var boxPen = new Pen(Color.FromArgb(140, 217, 119, 87), 1.1f))
|
|
3140
|
+
{
|
|
3141
|
+
fmt.FormatFlags |= StringFormatFlags.NoWrap;
|
|
3142
|
+
int drawn = 0;
|
|
3143
|
+
for (int i = 0; i < rawElements.Count && drawn < 120; i++)
|
|
3144
|
+
{
|
|
3145
|
+
var el = rawElements[i] as Dictionary<string, object>;
|
|
3146
|
+
if (el == null) continue;
|
|
3147
|
+
int ex = Convert.ToInt32(el["x"]), ey = Convert.ToInt32(el["y"]);
|
|
3148
|
+
int ew = Convert.ToInt32(el["width"]), eh = Convert.ToInt32(el["height"]);
|
|
3149
|
+
float rx = (float)((ex - sx) * scaleX);
|
|
3150
|
+
float ry = (float)((ey - sy) * scaleY);
|
|
3151
|
+
float rw = (float)(ew * scaleX);
|
|
3152
|
+
float rh = (float)(eh * scaleY);
|
|
3153
|
+
if (rx + rw < 0 || ry + rh < 0 || rx >= outW || ry >= outH) continue;
|
|
3154
|
+
if (rw < 4 || rh < 4) continue;
|
|
3155
|
+
el["mark"] = i + 1;
|
|
3156
|
+
drawn++;
|
|
3157
|
+
if (rw <= outW * 0.85f && rh <= outH * 0.85f)
|
|
3158
|
+
g.DrawRectangle(boxPen, rx, ry, rw, rh);
|
|
3159
|
+
string tag = (i + 1).ToString();
|
|
3160
|
+
SizeF ts = g.MeasureString(tag, font, 1000, fmt);
|
|
3161
|
+
float bw = Math.Max(16f, ts.Width + 6f);
|
|
3162
|
+
float bh = Math.Max(15f, ts.Height + 2f);
|
|
3163
|
+
float bx = Math.Max(1f, Math.Min(outW - bw - 1f, rx));
|
|
3164
|
+
float by = Math.Max(1f, Math.Min(outH - bh - 1f, ry - bh * 0.35f));
|
|
3165
|
+
var badge = new RectangleF(bx, by, bw, bh);
|
|
3166
|
+
for (int attempt = 0; attempt < 3; attempt++)
|
|
3167
|
+
{
|
|
3168
|
+
bool overlap = false;
|
|
3169
|
+
for (int j = 0; j < placed.Count; j++)
|
|
3170
|
+
if (placed[j].IntersectsWith(badge)) { overlap = true; break; }
|
|
3171
|
+
if (!overlap) break;
|
|
3172
|
+
badge.X = Math.Min(outW - bw - 1f, badge.X + bw + 2f);
|
|
3173
|
+
}
|
|
3174
|
+
placed.Add(badge);
|
|
3175
|
+
g.FillRectangle(bgBrush, badge);
|
|
3176
|
+
g.DrawRectangle(borderPen, badge.X, badge.Y, badge.Width, badge.Height);
|
|
3177
|
+
g.DrawString(tag, font, Brushes.White, badge.X + (badge.Width - ts.Width) / 2f, badge.Y + (badge.Height - ts.Height) / 2f - 0.5f, fmt);
|
|
3178
|
+
}
|
|
3179
|
+
}
|
|
3180
|
+
|
|
3181
|
+
using (var ms = new MemoryStream())
|
|
3182
|
+
{
|
|
3183
|
+
ImageCodecInfo jpeg = null;
|
|
3184
|
+
foreach (var c in ImageCodecInfo.GetImageEncoders()) if (c.MimeType == "image/jpeg") { jpeg = c; break; }
|
|
3185
|
+
if (jpeg != null)
|
|
3186
|
+
{
|
|
3187
|
+
using (var ep = new EncoderParameters(1))
|
|
3188
|
+
{
|
|
3189
|
+
ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)quality);
|
|
3190
|
+
canvas.Save(ms, jpeg, ep);
|
|
3191
|
+
}
|
|
3192
|
+
}
|
|
3193
|
+
else canvas.Save(ms, ImageFormat.Jpeg);
|
|
3194
|
+
|
|
3195
|
+
var outDict = new Dictionary<string, object>();
|
|
3196
|
+
if (ui != null) foreach (var kv in ui) outDict[kv.Key] = kv.Value;
|
|
3197
|
+
outDict["data"] = Convert.ToBase64String(ms.ToArray());
|
|
3198
|
+
outDict["width"] = outW;
|
|
3199
|
+
outDict["height"] = outH;
|
|
3200
|
+
outDict["via"] = via;
|
|
3201
|
+
return outDict;
|
|
3202
|
+
}
|
|
3203
|
+
}
|
|
3204
|
+
}
|
|
3205
|
+
|
|
2756
3206
|
static List<object> Collect(IntPtr hwnd, int max, bool includeText)
|
|
2757
3207
|
{
|
|
2758
3208
|
var root = AutomationElement.FromHandle(hwnd);
|
|
@@ -2769,6 +3219,8 @@ namespace DshComputerUse
|
|
|
2769
3219
|
cache.Add(AutomationElement.RuntimeIdProperty);
|
|
2770
3220
|
cache.Add(AutomationElement.ClassNameProperty);
|
|
2771
3221
|
cache.Add(AutomationElement.IsKeyboardFocusableProperty);
|
|
3222
|
+
cache.Add(AutomationElement.IsPasswordProperty);
|
|
3223
|
+
cache.Add(AutomationElement.NativeWindowHandleProperty);
|
|
2772
3224
|
cache.Add(ValuePattern.ValueProperty);
|
|
2773
3225
|
cache.Add(TogglePattern.ToggleStateProperty);
|
|
2774
3226
|
cache.AutomationElementMode = AutomationElementMode.None;
|
|
@@ -2787,9 +3239,22 @@ namespace DshComputerUse
|
|
|
2787
3239
|
// Web 编辑器的 contenteditable 常是 Group(ProseMirror/tiptap 等),
|
|
2788
3240
|
// 不是 Edit;保留这类 Group,其余 Group 跳过,避免淹没按钮。
|
|
2789
3241
|
if (type == ControlType.Group && !IsEditorClass(cls)) continue;
|
|
3242
|
+
bool isPwd = false;
|
|
3243
|
+
try
|
|
3244
|
+
{
|
|
3245
|
+
object pwdProp = el.GetCachedPropertyValue(AutomationElement.IsPasswordProperty, true);
|
|
3246
|
+
if (pwdProp is bool && (bool)pwdProp) isPwd = true;
|
|
3247
|
+
if (!isPwd)
|
|
3248
|
+
{
|
|
3249
|
+
object nhProp = el.GetCachedPropertyValue(AutomationElement.NativeWindowHandleProperty, true);
|
|
3250
|
+
if (nhProp is int && (int)nhProp != 0 && IsWin32PasswordHwnd(new IntPtr((int)nhProp))) isPwd = true;
|
|
3251
|
+
}
|
|
3252
|
+
}
|
|
3253
|
+
catch (Exception) { }
|
|
2790
3254
|
var d = new Dictionary<string, object>();
|
|
2791
3255
|
d["role"] = type == ControlType.Group ? "Edit" : type.ProgrammaticName.Replace("ControlType.", "");
|
|
2792
3256
|
if (type == ControlType.Group) d["editable"] = true;
|
|
3257
|
+
if (isPwd) d["password"] = true;
|
|
2793
3258
|
d["name"] = name.Length > 120 ? name.Substring(0, 120) + "…" : name;
|
|
2794
3259
|
string aid = (el.GetCachedPropertyValue(AutomationElement.AutomationIdProperty) as string) ?? "";
|
|
2795
3260
|
if (aid.Length > 0) d["automationId"] = aid;
|
|
@@ -2797,7 +3262,8 @@ namespace DshComputerUse
|
|
|
2797
3262
|
if (runtimeId != null && runtimeId.Length > 0) d["runtimeId"] = String.Join(",", runtimeId);
|
|
2798
3263
|
d["focusable"] = (bool)el.GetCachedPropertyValue(AutomationElement.IsKeyboardFocusableProperty);
|
|
2799
3264
|
object value = el.GetCachedPropertyValue(ValuePattern.ValueProperty, true);
|
|
2800
|
-
if (
|
|
3265
|
+
if (isPwd) { d["value"] = "[password]"; }
|
|
3266
|
+
else if (value is string && ((string)value).Length > 0) { var v = (string)value; d["value"] = v.Length > 120 ? v.Substring(0, 120) + "…" : v; }
|
|
2801
3267
|
object toggle = el.GetCachedPropertyValue(TogglePattern.ToggleStateProperty, true);
|
|
2802
3268
|
if (toggle is ToggleState) d["checked"] = (ToggleState)toggle == ToggleState.On;
|
|
2803
3269
|
if (!(bool)el.GetCachedPropertyValue(AutomationElement.IsEnabledProperty)) d["disabled"] = true;
|
|
@@ -2963,6 +3429,14 @@ namespace DshComputerUse
|
|
|
2963
3429
|
static DateTime shownAt;
|
|
2964
3430
|
static IntPtr hook = IntPtr.Zero;
|
|
2965
3431
|
static Native.LowLevelKeyboardProc hookProc;
|
|
3432
|
+
static IntPtr mouseHook = IntPtr.Zero;
|
|
3433
|
+
static Native.LowLevelMouseProc mouseHookProc;
|
|
3434
|
+
static readonly object UserActionLock = new object();
|
|
3435
|
+
static int lastClickTick = int.MinValue / 2;
|
|
3436
|
+
static int lastClickX, lastClickY;
|
|
3437
|
+
static int lastScrollTick = int.MinValue / 2;
|
|
3438
|
+
static int lastKeySummaryTick = int.MinValue / 2;
|
|
3439
|
+
static int keyBurstCount;
|
|
2966
3440
|
static volatile bool visible;
|
|
2967
3441
|
static volatile bool paused;
|
|
2968
3442
|
static volatile bool clickTargetEnabled = true;
|
|
@@ -2975,6 +3449,9 @@ namespace DshComputerUse
|
|
|
2975
3449
|
|
|
2976
3450
|
// The progress card ("pet"): replaces the pill while DeepSeek Harness is minimized.
|
|
2977
3451
|
static bool petMode;
|
|
3452
|
+
static string petSize = "standard";
|
|
3453
|
+
static string hoveredBtn = "";
|
|
3454
|
+
static string pressedBtn = "";
|
|
2978
3455
|
static LayeredForm pet;
|
|
2979
3456
|
public static volatile IntPtr PetHwnd = IntPtr.Zero;
|
|
2980
3457
|
static string petThinking = "";
|
|
@@ -3052,10 +3529,14 @@ namespace DshComputerUse
|
|
|
3052
3529
|
catch (Exception) { icon = null; }
|
|
3053
3530
|
}
|
|
3054
3531
|
petAlpha = (byte)Math.Max(90, Math.Min(255, Args.Int(r, "petOpacity", 90) * 255 / 100));
|
|
3532
|
+
string reqSize = Args.Str(r, "petSize", "");
|
|
3533
|
+
if (reqSize == "compact" || reqSize == "standard" || reqSize == "detailed") petSize = reqSize;
|
|
3055
3534
|
clickTargetEnabled = Args.Bool(r, "glow", true);
|
|
3056
3535
|
if (visible && !petFinished) { RenderPill(); return; }
|
|
3057
3536
|
if (visible) HideCore(); // the previous run's "done" card is still up
|
|
3058
3537
|
petMode = Args.Bool(r, "pet", false);
|
|
3538
|
+
hoveredBtn = "";
|
|
3539
|
+
pressedBtn = "";
|
|
3059
3540
|
petThinking = Args.Str(r, "thinking", "");
|
|
3060
3541
|
petSteps = new List<string>();
|
|
3061
3542
|
if (status.Length > 0) petSteps.Add(status);
|
|
@@ -3079,10 +3560,38 @@ namespace DshComputerUse
|
|
|
3079
3560
|
if (pet == null)
|
|
3080
3561
|
{
|
|
3081
3562
|
pet = new LayeredForm(false);
|
|
3563
|
+
pet.MouseMove += delegate (object s, MouseEventArgs e)
|
|
3564
|
+
{
|
|
3565
|
+
string hit = "";
|
|
3566
|
+
foreach (var b in buttons) if (b.Key.Contains(e.Location)) { hit = b.Value; break; }
|
|
3567
|
+
pet.Cursor = hit.Length > 0 ? Cursors.Hand : Cursors.SizeAll;
|
|
3568
|
+
if (hit != hoveredBtn)
|
|
3569
|
+
{
|
|
3570
|
+
hoveredBtn = hit;
|
|
3571
|
+
RenderPill();
|
|
3572
|
+
}
|
|
3573
|
+
};
|
|
3574
|
+
pet.MouseLeave += delegate
|
|
3575
|
+
{
|
|
3576
|
+
if (hoveredBtn.Length > 0 || pressedBtn.Length > 0)
|
|
3577
|
+
{
|
|
3578
|
+
hoveredBtn = "";
|
|
3579
|
+
pressedBtn = "";
|
|
3580
|
+
RenderPill();
|
|
3581
|
+
}
|
|
3582
|
+
};
|
|
3082
3583
|
pet.MouseDown += delegate (object s, MouseEventArgs e)
|
|
3083
3584
|
{
|
|
3084
3585
|
if (e.Button != MouseButtons.Left) return;
|
|
3085
|
-
foreach (var b in buttons)
|
|
3586
|
+
foreach (var b in buttons)
|
|
3587
|
+
{
|
|
3588
|
+
if (b.Key.Contains(e.Location))
|
|
3589
|
+
{
|
|
3590
|
+
pressedBtn = b.Value;
|
|
3591
|
+
RenderPill();
|
|
3592
|
+
return;
|
|
3593
|
+
}
|
|
3594
|
+
}
|
|
3086
3595
|
// Drag the card anywhere; it keeps that place until the next run.
|
|
3087
3596
|
Native.ReleaseCapture();
|
|
3088
3597
|
Native.SendMessage(pet.Handle, 0xA1, new IntPtr(2), IntPtr.Zero); // WM_NCLBUTTONDOWN, HTCAPTION
|
|
@@ -3093,9 +3602,12 @@ namespace DshComputerUse
|
|
|
3093
3602
|
};
|
|
3094
3603
|
pet.MouseUp += delegate (object s, MouseEventArgs e)
|
|
3095
3604
|
{
|
|
3605
|
+
bool hadPressed = pressedBtn.Length > 0;
|
|
3606
|
+
pressedBtn = "";
|
|
3096
3607
|
if (petDragged) { petDragged = false; return; }
|
|
3097
3608
|
foreach (var b in buttons)
|
|
3098
|
-
if (b.Key.Contains(e.Location)) { Press(b.Value);
|
|
3609
|
+
if (b.Key.Contains(e.Location)) { Press(b.Value); return; }
|
|
3610
|
+
if (hadPressed) RenderPill();
|
|
3099
3611
|
};
|
|
3100
3612
|
pet.Show();
|
|
3101
3613
|
PetHwnd = pet.Handle;
|
|
@@ -3347,13 +3859,51 @@ namespace DshComputerUse
|
|
|
3347
3859
|
}
|
|
3348
3860
|
}
|
|
3349
3861
|
|
|
3862
|
+
static int lastMarkX, lastMarkY;
|
|
3863
|
+
static bool hasLastMark;
|
|
3864
|
+
|
|
3350
3865
|
public static void MarkPointer(int x, int y, string text, int holdMs)
|
|
3351
3866
|
{
|
|
3352
|
-
|
|
3867
|
+
GlideMark(x, y, text, Accent, holdMs, false, false);
|
|
3868
|
+
}
|
|
3869
|
+
|
|
3870
|
+
/** Smooth single-segment EaseOutCubic glide (~160ms) to (x, y) before holding the Codex cursor. */
|
|
3871
|
+
public static void GlideMark(int x, int y, string text, Color color, int holdMs, bool capturable, bool ripple)
|
|
3872
|
+
{
|
|
3873
|
+
int startX, startY;
|
|
3874
|
+
if (hasLastMark)
|
|
3875
|
+
{
|
|
3876
|
+
startX = lastMarkX;
|
|
3877
|
+
startY = lastMarkY;
|
|
3878
|
+
}
|
|
3879
|
+
else
|
|
3880
|
+
{
|
|
3881
|
+
Native.POINT cur;
|
|
3882
|
+
if (Native.GetCursorPos(out cur)) { startX = cur.X; startY = cur.Y; }
|
|
3883
|
+
else { startX = x; startY = y; }
|
|
3884
|
+
}
|
|
3885
|
+
double dist = Math.Sqrt((double)(x - startX) * (x - startX) + (double)(y - startY) * (y - startY));
|
|
3886
|
+
if (dist >= 40.0)
|
|
3887
|
+
{
|
|
3888
|
+
int steps = Math.Max(5, Math.Min(10, (int)(dist / 90.0) + 5));
|
|
3889
|
+
for (int i = 1; i < steps; i++)
|
|
3890
|
+
{
|
|
3891
|
+
double t = (double)i / steps;
|
|
3892
|
+
double ease = 1.0 - Math.Pow(1.0 - t, 3.0); // EaseOutCubic
|
|
3893
|
+
int ix = startX + (int)Math.Round((x - startX) * ease);
|
|
3894
|
+
int iy = startY + (int)Math.Round((y - startY) * ease);
|
|
3895
|
+
Mark(ix, iy, text, color, holdMs, capturable, false);
|
|
3896
|
+
Thread.Sleep(16);
|
|
3897
|
+
}
|
|
3898
|
+
}
|
|
3899
|
+
Mark(x, y, text, color, holdMs, capturable, ripple);
|
|
3353
3900
|
}
|
|
3354
3901
|
|
|
3355
3902
|
public static void Mark(int x, int y, string text, Color color, int holdMs, bool capturable, bool ripple)
|
|
3356
3903
|
{
|
|
3904
|
+
lastMarkX = x;
|
|
3905
|
+
lastMarkY = y;
|
|
3906
|
+
hasLastMark = true;
|
|
3357
3907
|
Ensure();
|
|
3358
3908
|
Ui(delegate
|
|
3359
3909
|
{
|
|
@@ -3630,6 +4180,18 @@ namespace DshComputerUse
|
|
|
3630
4180
|
return "…" + s.Substring(Math.Min(lo, s.Length));
|
|
3631
4181
|
}
|
|
3632
4182
|
|
|
4183
|
+
static string ButtonTip(string act)
|
|
4184
|
+
{
|
|
4185
|
+
if (act == "stop") return "停止本轮";
|
|
4186
|
+
if (act == "pause") return "暂停操控";
|
|
4187
|
+
if (act == "resume") return "继续操控";
|
|
4188
|
+
if (act == "expand") return petExpanded ? "收起详情" : "展开详情";
|
|
4189
|
+
if (act == "input") return input != null ? "关闭输入框" : "输入新指令";
|
|
4190
|
+
if (act == "close") return "关闭卡片";
|
|
4191
|
+
if (act == "send") return "发送指令";
|
|
4192
|
+
return "";
|
|
4193
|
+
}
|
|
4194
|
+
|
|
3633
4195
|
static void RenderPet()
|
|
3634
4196
|
{
|
|
3635
4197
|
if (pet == null) return;
|
|
@@ -3644,15 +4206,22 @@ namespace DshComputerUse
|
|
|
3644
4206
|
}
|
|
3645
4207
|
rendered = Key();
|
|
3646
4208
|
bool dark = DarkTheme();
|
|
3647
|
-
Color bg = dark ? Color.FromArgb(petAlpha,
|
|
4209
|
+
Color bg = dark ? Color.FromArgb(petAlpha, 30, 30, 32) : Color.FromArgb(petAlpha, 252, 252, 251);
|
|
3648
4210
|
Color ink = dark ? Color.FromArgb(244, 243, 241) : Color.FromArgb(31, 30, 29);
|
|
3649
4211
|
Color muted = dark ? Color.FromArgb(168, 165, 160) : Color.FromArgb(112, 110, 106);
|
|
3650
|
-
Color edge = dark ? Color.FromArgb(
|
|
3651
|
-
Color chip = dark ? Color.FromArgb(
|
|
3652
|
-
Color
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
4212
|
+
Color edge = dark ? Color.FromArgb(64, 255, 255, 255) : Color.FromArgb(38, 0, 0, 0);
|
|
4213
|
+
Color chip = dark ? Color.FromArgb(64, 63, 66) : Color.FromArgb(236, 234, 230);
|
|
4214
|
+
Color chipHover = dark ? Color.FromArgb(92, 86, 82) : Color.FromArgb(224, 214, 206);
|
|
4215
|
+
Color chipPress = dark ? Color.FromArgb(110, 96, 88) : Color.FromArgb(212, 198, 188);
|
|
4216
|
+
Color field = dark ? Color.FromArgb(50, 50, 52) : Color.White;
|
|
4217
|
+
|
|
4218
|
+
bool isCompact = petSize == "compact";
|
|
4219
|
+
bool isDetailed = petSize == "detailed";
|
|
4220
|
+
string title = petFinished ? "已完成" : (isCompact && label.Length > 12 ? label.Substring(0, 11) + "…" : label);
|
|
4221
|
+
string hoverTip = ButtonTip(hoveredBtn);
|
|
4222
|
+
string state = hoverTip.Length > 0 ? hoverTip
|
|
4223
|
+
: petFinished ? "" : paused ? (input != null ? "输入指令中…" : "已暂停 · Esc 继续")
|
|
4224
|
+
: Typing() ? "你正在操作,已暂停" : (isCompact ? "" : "Esc 暂停");
|
|
3656
4225
|
// Header buttons, right to left.
|
|
3657
4226
|
var actions = new List<string>(); var glyphs = new List<string>();
|
|
3658
4227
|
if (petFinished) { actions.Add("close"); glyphs.Add("\uE711"); }
|
|
@@ -3667,24 +4236,29 @@ namespace DshComputerUse
|
|
|
3667
4236
|
float s = scale, px = 1.333f * scale;
|
|
3668
4237
|
int shadow = (int)(14 * s);
|
|
3669
4238
|
petShadow = shadow;
|
|
3670
|
-
float bodyW =
|
|
3671
|
-
float
|
|
4239
|
+
float bodyW = (isCompact ? 320f : isDetailed ? 484f : 420f) * s;
|
|
4240
|
+
float pad = (isCompact ? 13f : 16f) * s;
|
|
4241
|
+
float headH = (isCompact ? 40f : 44f) * s;
|
|
4242
|
+
bool showThinking = !isCompact || petExpanded;
|
|
4243
|
+
bool showTimeline = petExpanded || isDetailed;
|
|
4244
|
+
float replyH = showThinking ? (isDetailed && !petExpanded ? 42f * s : 26f * s) : 0f;
|
|
3672
4245
|
string progress = petFinished ? "已交还电脑控制" : petThinking.Length > 0 ? "思考 · " + petThinking : "正在操作,等待下一步…";
|
|
3673
|
-
if (petExpanded)
|
|
4246
|
+
if (showThinking && (petExpanded || isDetailed))
|
|
3674
4247
|
{
|
|
3675
|
-
// Grow with the reply, up to about eight lines.
|
|
3676
4248
|
using (var probe = new Bitmap(1, 1))
|
|
3677
4249
|
using (var pg = Graphics.FromImage(probe))
|
|
3678
|
-
using (var pf = new Font("Microsoft YaHei UI", 10.5f * 1.333f * scale, FontStyle.Regular, GraphicsUnit.Pixel))
|
|
4250
|
+
using (var pf = new Font("Microsoft YaHei UI", (isCompact ? 9.5f : 10.5f) * 1.333f * scale, FontStyle.Regular, GraphicsUnit.Pixel))
|
|
3679
4251
|
{
|
|
3680
|
-
float need = pg.MeasureString(progress, pf, new SizeF(
|
|
3681
|
-
|
|
4252
|
+
float need = pg.MeasureString(progress, pf, new SizeF(bodyW - 2 * pad, 100000), new StringFormat(StringFormat.GenericTypographic)).Height + 6 * scale;
|
|
4253
|
+
float cap = petExpanded ? (isDetailed ? 210f : 172f) * scale : 44f * scale;
|
|
4254
|
+
replyH = Math.Max(26f * scale, Math.Min(cap, need));
|
|
3682
4255
|
}
|
|
3683
4256
|
}
|
|
3684
|
-
int
|
|
3685
|
-
|
|
4257
|
+
int maxSteps = petExpanded ? (isDetailed ? 8 : 5) : (isDetailed ? 3 : 0);
|
|
4258
|
+
int stepRows = showTimeline ? Math.Min(maxSteps, Math.Max(1, petSteps.Count)) : 0;
|
|
4259
|
+
float listH = showTimeline ? 10 * s + stepRows * 22 * s : 24 * s;
|
|
3686
4260
|
float inputH = input != null ? 46 * s : 0;
|
|
3687
|
-
float bodyH = headH + replyH + listH + inputH +
|
|
4261
|
+
float bodyH = headH + replyH + listH + inputH + (isCompact ? 10f : 12f) * s;
|
|
3688
4262
|
int W = (int)Math.Ceiling(bodyW) + 2 * shadow, H = (int)Math.Ceiling(bodyH) + 2 * shadow;
|
|
3689
4263
|
if (petAnchor.IsEmpty) petAnchor = new Point(work.Right - (int)(16 * s), work.Bottom - (int)(16 * s));
|
|
3690
4264
|
int x = petAnchor.X - (int)bodyW - shadow, y = petAnchor.Y - (int)bodyH - shadow;
|
|
@@ -3693,8 +4267,8 @@ namespace DshComputerUse
|
|
|
3693
4267
|
|
|
3694
4268
|
string glyphFont = IconFont();
|
|
3695
4269
|
using (var fHead = new Font("Microsoft YaHei UI", 8.5f * px, FontStyle.Bold, GraphicsUnit.Pixel))
|
|
3696
|
-
using (var fState = new Font("Microsoft YaHei UI",
|
|
3697
|
-
using (var fText = new Font("Microsoft YaHei UI",
|
|
4270
|
+
using (var fState = new Font("Microsoft YaHei UI", 8.2f * px, FontStyle.Regular, GraphicsUnit.Pixel))
|
|
4271
|
+
using (var fText = new Font("Microsoft YaHei UI", (isCompact ? 9.5f : 10.2f) * px, FontStyle.Regular, GraphicsUnit.Pixel))
|
|
3698
4272
|
using (var fAct = new Font("Microsoft YaHei UI", 8.5f * px, FontStyle.Regular, GraphicsUnit.Pixel))
|
|
3699
4273
|
using (var fGlyph = new Font(glyphFont.Length > 0 ? glyphFont : "Segoe UI Symbol", 8.5f * px, FontStyle.Regular, GraphicsUnit.Pixel))
|
|
3700
4274
|
using (var bmp = new Bitmap(W, H, PixelFormat.Format32bppArgb))
|
|
@@ -3711,7 +4285,7 @@ namespace DshComputerUse
|
|
|
3711
4285
|
var center = new StringFormat(); center.Alignment = StringAlignment.Center; center.LineAlignment = StringAlignment.Center;
|
|
3712
4286
|
|
|
3713
4287
|
var body = new RectangleF(shadow, shadow, bodyW, bodyH);
|
|
3714
|
-
float radius =
|
|
4288
|
+
float radius = (isCompact ? 15f : 18f) * s;
|
|
3715
4289
|
for (int i = shadow; i > 0; i--)
|
|
3716
4290
|
{
|
|
3717
4291
|
double f = 1.0 - (double)i / shadow;
|
|
@@ -3721,11 +4295,11 @@ namespace DshComputerUse
|
|
|
3721
4295
|
using (var path = Rounded(body, radius))
|
|
3722
4296
|
{
|
|
3723
4297
|
using (var brush = new SolidBrush(bg)) g.FillPath(brush, path);
|
|
3724
|
-
using (var pen = new Pen(edge, Math.Max(1f, s))) g.DrawPath(pen, path);
|
|
4298
|
+
using (var pen = new Pen(petFinished ? Color.FromArgb(145, 46, 160, 67) : edge, Math.Max(1f, s))) g.DrawPath(pen, path);
|
|
3725
4299
|
}
|
|
3726
4300
|
|
|
3727
|
-
// Header: logo, title, state, round icon buttons.
|
|
3728
|
-
float hy = body.Y +
|
|
4301
|
+
// Header: logo, title, state / button hover tooltip, tactile round icon buttons.
|
|
4302
|
+
float hy = body.Y + (isCompact ? 8f : 10f) * s, hh = 26 * s;
|
|
3729
4303
|
float iconSize = 18 * s;
|
|
3730
4304
|
var iconRect = new RectangleF(body.X + pad, hy + (hh - iconSize) / 2f, iconSize, iconSize);
|
|
3731
4305
|
Image logo = dark ? icon : (iconLight ?? icon);
|
|
@@ -3742,56 +4316,85 @@ namespace DshComputerUse
|
|
|
3742
4316
|
tx += headSize.Width + 8 * s;
|
|
3743
4317
|
|
|
3744
4318
|
buttons.Clear();
|
|
3745
|
-
float d =
|
|
4319
|
+
float d = (isCompact ? 24f : 26f) * s, bx = body.Right - pad;
|
|
3746
4320
|
for (int i = 0; i < actions.Count; i++)
|
|
3747
4321
|
{
|
|
4322
|
+
string act = actions[i];
|
|
3748
4323
|
bx -= d;
|
|
3749
|
-
var
|
|
3750
|
-
bool stop =
|
|
3751
|
-
bool on = (
|
|
3752
|
-
|
|
3753
|
-
|
|
3754
|
-
|
|
3755
|
-
|
|
4324
|
+
var hitRect = new RectangleF(bx, hy + (hh - d) / 2f, d, d);
|
|
4325
|
+
bool stop = act == "stop";
|
|
4326
|
+
bool on = (act == "input" && input != null) || (act == "resume");
|
|
4327
|
+
bool hover = hoveredBtn == act;
|
|
4328
|
+
bool press = pressedBtn == act;
|
|
4329
|
+
float inflate = press ? -0.8f * s : hover ? 1.1f * s : 0f;
|
|
4330
|
+
var circle = RectangleF.Inflate(hitRect, inflate, inflate);
|
|
4331
|
+
if (hover && stop)
|
|
4332
|
+
{
|
|
4333
|
+
using (var halo = new SolidBrush(Color.FromArgb(65, Accent)))
|
|
4334
|
+
g.FillEllipse(halo, RectangleF.Inflate(circle, 2.6f * s, 2.6f * s));
|
|
4335
|
+
}
|
|
4336
|
+
Color btnFill = stop
|
|
4337
|
+
? (press ? Color.FromArgb(190, 92, 62) : hover ? AccentHi : Accent)
|
|
4338
|
+
: on
|
|
4339
|
+
? Color.FromArgb(dark ? (hover ? 145 : 115) : (hover ? 95 : 65), Accent)
|
|
4340
|
+
: (press ? chipPress : hover ? chipHover : chip);
|
|
4341
|
+
using (var brush = new SolidBrush(btnFill)) g.FillEllipse(brush, circle);
|
|
4342
|
+
if (hover && !stop)
|
|
4343
|
+
{
|
|
4344
|
+
using (var ring = new Pen(Color.FromArgb(dark ? 150 : 120, Accent), Math.Max(1f, 1.2f * s)))
|
|
4345
|
+
g.DrawEllipse(ring, circle);
|
|
4346
|
+
}
|
|
4347
|
+
string glyph = glyphFont.Length > 0 ? glyphs[i] : (stop ? "■" : act == "pause" ? "❚❚" : act == "resume" ? "▶" : act == "expand" ? (petExpanded ? "˅" : "˄") : act == "close" ? "✕" : "✎");
|
|
4348
|
+
Color glyphColor = stop ? Color.White : (hover || on) ? (dark ? Color.White : Color.FromArgb(168, 72, 42)) : ink;
|
|
4349
|
+
using (var b = new SolidBrush(glyphColor)) g.DrawString(glyph, fGlyph, b, circle, center);
|
|
4350
|
+
buttons.Add(new KeyValuePair<Rectangle, string>(Rectangle.Round(hitRect), act));
|
|
3756
4351
|
bx -= 6 * s;
|
|
3757
4352
|
}
|
|
3758
4353
|
if (state.Length > 0)
|
|
3759
4354
|
{
|
|
3760
4355
|
string st = Tail(g, state, fState, Math.Max(0, bx - tx - 4 * s), fmt);
|
|
3761
4356
|
SizeF stSize = g.MeasureString(st, fState, 100000, fmt);
|
|
3762
|
-
|
|
4357
|
+
Color stColor = (hoverTip.Length > 0 || paused) ? Accent : muted;
|
|
4358
|
+
using (var b = new SolidBrush(stColor)) g.DrawString(st, fState, b, tx, hy + (hh - stSize.Height) / 2f, fmt);
|
|
3763
4359
|
}
|
|
3764
4360
|
|
|
3765
4361
|
// Reasoning and operations use separate rows throughout.
|
|
3766
4362
|
float lineW = bodyW - 2 * pad;
|
|
3767
4363
|
float ry = body.Y + headH;
|
|
3768
|
-
|
|
4364
|
+
if (showThinking)
|
|
3769
4365
|
{
|
|
3770
|
-
|
|
3771
|
-
g.DrawString(TailWrapped(g, progress, fText, lineW, replyH, wrap), fText, b, new RectangleF(body.X + pad, ry, lineW, replyH), wrap);
|
|
3772
|
-
else
|
|
4366
|
+
using (var b = new SolidBrush(petThinking.Length > 0 && !petFinished ? ink : muted))
|
|
3773
4367
|
{
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
|
|
3778
|
-
|
|
4368
|
+
if (petExpanded || isDetailed)
|
|
4369
|
+
g.DrawString(TailWrapped(g, progress, fText, lineW, replyH, wrap), fText, b, new RectangleF(body.X + pad, ry, lineW, replyH), wrap);
|
|
4370
|
+
else
|
|
4371
|
+
{
|
|
4372
|
+
string shown = petThinking.Length > 0 && !petFinished
|
|
4373
|
+
? "思考 · " + Tail(g, petThinking, fText, lineW - g.MeasureString("思考 · ", fText, 100000, fmt).Width, fmt)
|
|
4374
|
+
: Tail(g, progress, fText, lineW, fmt);
|
|
4375
|
+
SizeF size = g.MeasureString(shown.Length > 0 ? shown : " ", fText, 100000, fmt);
|
|
4376
|
+
g.DrawString(shown, fText, b, body.X + pad, ry + (replyH - size.Height) / 2f, fmt);
|
|
4377
|
+
}
|
|
3779
4378
|
}
|
|
3780
4379
|
}
|
|
3781
4380
|
|
|
3782
4381
|
// Thinking and the step timeline.
|
|
3783
4382
|
float ly = ry + replyH;
|
|
3784
|
-
if (
|
|
4383
|
+
if (showTimeline)
|
|
3785
4384
|
{
|
|
3786
4385
|
ly += 4 * s;
|
|
3787
4386
|
using (var pen = new Pen(edge, Math.Max(1f, s))) g.DrawLine(pen, body.X + pad, ly, body.Right - pad, ly);
|
|
3788
|
-
ly +=
|
|
4387
|
+
ly += 5 * s;
|
|
3789
4388
|
int first = Math.Max(0, petSteps.Count - stepRows);
|
|
3790
4389
|
for (int i = first; i < petSteps.Count; i++)
|
|
3791
4390
|
{
|
|
3792
4391
|
bool current = i == petSteps.Count - 1 && !petFinished;
|
|
3793
4392
|
float cy = ly + 11 * s;
|
|
3794
|
-
if (current)
|
|
4393
|
+
if (current)
|
|
4394
|
+
{
|
|
4395
|
+
using (var halo = new SolidBrush(Color.FromArgb(60, Accent))) g.FillEllipse(halo, body.X + pad, cy - 5 * s, 10 * s, 10 * s);
|
|
4396
|
+
using (var brush = new SolidBrush(Accent)) g.FillEllipse(brush, body.X + pad + 2 * s, cy - 3 * s, 6 * s, 6 * s);
|
|
4397
|
+
}
|
|
3795
4398
|
else using (var b = new SolidBrush(Color.FromArgb(46, 160, 67))) g.DrawString(glyphFont.Length > 0 ? "\uE73E" : "✓", fGlyph, b, new RectangleF(body.X + pad - 2 * s, ly, 14 * s, 22 * s), center);
|
|
3796
4399
|
string line = Tail(g, petSteps[i], fAct, lineW - 16 * s, fmt);
|
|
3797
4400
|
using (var b = new SolidBrush(current ? ink : muted)) g.DrawString(line, fAct, b, body.X + pad + 16 * s, ly + 3 * s, fmt);
|
|
@@ -3802,15 +4405,17 @@ namespace DshComputerUse
|
|
|
3802
4405
|
{
|
|
3803
4406
|
string act;
|
|
3804
4407
|
if (petFinished) act = petSteps.Count > 0 ? "最后操作 · " + petSteps[petSteps.Count - 1] : "";
|
|
4408
|
+
else if (isCompact) act = petSteps.Count > 0 ? petSteps[petSteps.Count - 1] : "准备操作…";
|
|
3805
4409
|
else
|
|
3806
4410
|
{
|
|
3807
4411
|
var parts = new List<string>();
|
|
3808
4412
|
for (int i = Math.Max(0, petSteps.Count - 4); i < petSteps.Count; i++) parts.Add(i < petSteps.Count - 1 ? "✓ " + petSteps[i] : petSteps[i]);
|
|
3809
4413
|
act = string.Join(" › ", parts);
|
|
3810
4414
|
}
|
|
4415
|
+
if (!petFinished) using (var halo = new SolidBrush(Color.FromArgb(55, Accent))) g.FillEllipse(halo, body.X + pad - 2 * s, ly + 6 * s, 10 * s, 10 * s);
|
|
3811
4416
|
using (var brush = new SolidBrush(petFinished ? Color.FromArgb(46, 160, 67) : Accent)) g.FillEllipse(brush, body.X + pad, ly + 8 * s, 6 * s, 6 * s);
|
|
3812
4417
|
string shown = Tail(g, act, fAct, lineW - 14 * s, fmt);
|
|
3813
|
-
using (var b = new SolidBrush(muted)) g.DrawString(shown, fAct, b, body.X + pad + 14 * s, ly + 3 * s, fmt);
|
|
4418
|
+
using (var b = new SolidBrush(isCompact ? ink : muted)) g.DrawString(shown, fAct, b, body.X + pad + 14 * s, ly + 3 * s, fmt);
|
|
3814
4419
|
ly += 24 * s;
|
|
3815
4420
|
}
|
|
3816
4421
|
|
|
@@ -3825,10 +4430,14 @@ namespace DshComputerUse
|
|
|
3825
4430
|
using (var brush = new SolidBrush(field)) g.FillPath(brush, path);
|
|
3826
4431
|
using (var pen = new Pen(Color.FromArgb(150, Accent), Math.Max(1f, 1.2f * s))) g.DrawPath(pen, path);
|
|
3827
4432
|
}
|
|
3828
|
-
|
|
3829
|
-
|
|
4433
|
+
bool sendHover = hoveredBtn == "send";
|
|
4434
|
+
bool sendPress = pressedBtn == "send";
|
|
4435
|
+
var sendHit = new RectangleF(body.Right - pad - sendD, ly + (34 * s - sendD) / 2f, sendD, sendD);
|
|
4436
|
+
var send = RectangleF.Inflate(sendHit, sendPress ? -0.8f * s : sendHover ? 1.1f * s : 0f, sendPress ? -0.8f * s : sendHover ? 1.1f * s : 0f);
|
|
4437
|
+
if (sendHover) using (var halo = new SolidBrush(Color.FromArgb(65, Accent))) g.FillEllipse(halo, RectangleF.Inflate(send, 2.5f * s, 2.5f * s));
|
|
4438
|
+
using (var brush = new SolidBrush(sendPress ? Color.FromArgb(190, 92, 62) : sendHover ? AccentHi : Accent)) g.FillEllipse(brush, send);
|
|
3830
4439
|
using (var b = new SolidBrush(Color.White)) g.DrawString(glyphFont.Length > 0 ? "\uE724" : "➤", fGlyph, b, send, center);
|
|
3831
|
-
buttons.Add(new KeyValuePair<Rectangle, string>(Rectangle.Round(
|
|
4440
|
+
buttons.Add(new KeyValuePair<Rectangle, string>(Rectangle.Round(sendHit), "send"));
|
|
3832
4441
|
var boxRect = new Rectangle(x + (int)(fieldRect.X + 14 * s), y + (int)(fieldRect.Y + 3 * s), (int)(fieldRect.Width - 28 * s), (int)(fieldRect.Height - 6 * s));
|
|
3833
4442
|
if (boxRect != inputBounds) { inputBounds = boxRect; input.Place(boxRect); }
|
|
3834
4443
|
}
|
|
@@ -3928,16 +4537,167 @@ namespace DshComputerUse
|
|
|
3928
4537
|
|
|
3929
4538
|
static void InstallHook()
|
|
3930
4539
|
{
|
|
3931
|
-
if (hook
|
|
3932
|
-
|
|
3933
|
-
|
|
4540
|
+
if (hook == IntPtr.Zero)
|
|
4541
|
+
{
|
|
4542
|
+
hookProc = HookCallback;
|
|
4543
|
+
hook = Native.SetWindowsHookEx(13, hookProc, Native.GetModuleHandle(null), 0);
|
|
4544
|
+
}
|
|
4545
|
+
if (mouseHook == IntPtr.Zero)
|
|
4546
|
+
{
|
|
4547
|
+
mouseHookProc = MouseHookCallback;
|
|
4548
|
+
mouseHook = Native.SetWindowsHookEx(14, mouseHookProc, Native.GetModuleHandle(null), 0);
|
|
4549
|
+
}
|
|
3934
4550
|
}
|
|
3935
4551
|
|
|
3936
4552
|
static void RemoveHook()
|
|
3937
4553
|
{
|
|
3938
|
-
if (hook
|
|
3939
|
-
|
|
3940
|
-
|
|
4554
|
+
if (hook != IntPtr.Zero)
|
|
4555
|
+
{
|
|
4556
|
+
Native.UnhookWindowsHookEx(hook);
|
|
4557
|
+
hook = IntPtr.Zero;
|
|
4558
|
+
}
|
|
4559
|
+
if (mouseHook != IntPtr.Zero)
|
|
4560
|
+
{
|
|
4561
|
+
Native.UnhookWindowsHookEx(mouseHook);
|
|
4562
|
+
mouseHook = IntPtr.Zero;
|
|
4563
|
+
}
|
|
4564
|
+
}
|
|
4565
|
+
|
|
4566
|
+
static bool IsOnOwnUi(int x, int y)
|
|
4567
|
+
{
|
|
4568
|
+
lock (RectLock)
|
|
4569
|
+
{
|
|
4570
|
+
if (!pillRect.IsEmpty && pillRect.Contains(x, y)) return true;
|
|
4571
|
+
if (pet != null && !pet.Physical.IsEmpty && pet.Physical.Contains(x, y)) return true;
|
|
4572
|
+
if (!inputBounds.IsEmpty && inputBounds.Contains(x, y)) return true;
|
|
4573
|
+
}
|
|
4574
|
+
IntPtr card = CardLayer.Hwnd;
|
|
4575
|
+
if (card != IntPtr.Zero && Native.IsWindow(card))
|
|
4576
|
+
{
|
|
4577
|
+
Native.RECT rc;
|
|
4578
|
+
if (Native.GetWindowRect(card, out rc) && x >= rc.Left && x < rc.Right && y >= rc.Top && y < rc.Bottom)
|
|
4579
|
+
return true;
|
|
4580
|
+
}
|
|
4581
|
+
return false;
|
|
4582
|
+
}
|
|
4583
|
+
|
|
4584
|
+
static void RecordUserMouseAsync(string kind, string button, string direction, int x, int y)
|
|
4585
|
+
{
|
|
4586
|
+
ThreadPool.QueueUserWorkItem(delegate
|
|
4587
|
+
{
|
|
4588
|
+
try
|
|
4589
|
+
{
|
|
4590
|
+
var win = Windows.At(x, y);
|
|
4591
|
+
string exe = win.ContainsKey("exe") ? Convert.ToString(win["exe"]) ?? "" : "";
|
|
4592
|
+
string title = win.ContainsKey("title") ? Convert.ToString(win["title"]) ?? "" : "";
|
|
4593
|
+
string exeLower = exe.ToLowerInvariant();
|
|
4594
|
+
// Clicking the DSH chat window itself is the user reading/chatting, not taking over target apps.
|
|
4595
|
+
if (exeLower == "cu-helper.exe" || exeLower == "deepseek harness.exe") return;
|
|
4596
|
+
string role = "", name = "";
|
|
4597
|
+
bool isPassword = false;
|
|
4598
|
+
if (kind == "click" || kind == "double_click")
|
|
4599
|
+
Uia.DescribeAtPoint(x, y, out role, out name, out isPassword);
|
|
4600
|
+
var data = new Dictionary<string, object>();
|
|
4601
|
+
data["kind"] = kind;
|
|
4602
|
+
if (!string.IsNullOrEmpty(button)) data["button"] = button;
|
|
4603
|
+
if (!string.IsNullOrEmpty(direction)) data["direction"] = direction;
|
|
4604
|
+
data["x"] = x;
|
|
4605
|
+
data["y"] = y;
|
|
4606
|
+
if (exe.Length > 0) data["exe"] = exe;
|
|
4607
|
+
if (title.Length > 0) data["title"] = title.Length > 80 ? title.Substring(0, 80) + "…" : title;
|
|
4608
|
+
if (role.Length > 0) data["role"] = role;
|
|
4609
|
+
if (name.Length > 0) data["name"] = name;
|
|
4610
|
+
if (isPassword) data["password"] = true;
|
|
4611
|
+
Program.EmitDataEvent("user_action", data);
|
|
4612
|
+
}
|
|
4613
|
+
catch (Exception) { }
|
|
4614
|
+
});
|
|
4615
|
+
}
|
|
4616
|
+
|
|
4617
|
+
static void RecordUserKeyAsync(int count)
|
|
4618
|
+
{
|
|
4619
|
+
ThreadPool.QueueUserWorkItem(delegate
|
|
4620
|
+
{
|
|
4621
|
+
try
|
|
4622
|
+
{
|
|
4623
|
+
IntPtr fg = Native.GetForegroundWindow();
|
|
4624
|
+
var win = Windows.Describe(fg);
|
|
4625
|
+
string exe = win.ContainsKey("exe") ? Convert.ToString(win["exe"]) ?? "" : "";
|
|
4626
|
+
string title = win.ContainsKey("title") ? Convert.ToString(win["title"]) ?? "" : "";
|
|
4627
|
+
string exeLower = exe.ToLowerInvariant();
|
|
4628
|
+
if (exeLower == "cu-helper.exe" || exeLower == "deepseek harness.exe") return;
|
|
4629
|
+
string role, name;
|
|
4630
|
+
bool isPassword;
|
|
4631
|
+
Uia.DescribeFocused(out role, out name, out isPassword);
|
|
4632
|
+
var data = new Dictionary<string, object>();
|
|
4633
|
+
data["kind"] = "type";
|
|
4634
|
+
data["keys"] = count;
|
|
4635
|
+
if (exe.Length > 0) data["exe"] = exe;
|
|
4636
|
+
if (title.Length > 0) data["title"] = title.Length > 80 ? title.Substring(0, 80) + "…" : title;
|
|
4637
|
+
if (role.Length > 0) data["role"] = role;
|
|
4638
|
+
if (name.Length > 0) data["name"] = name;
|
|
4639
|
+
if (isPassword) data["password"] = true;
|
|
4640
|
+
Program.EmitDataEvent("user_action", data);
|
|
4641
|
+
}
|
|
4642
|
+
catch (Exception) { }
|
|
4643
|
+
});
|
|
4644
|
+
}
|
|
4645
|
+
|
|
4646
|
+
static IntPtr MouseHookCallback(int nCode, IntPtr wParam, IntPtr lParam)
|
|
4647
|
+
{
|
|
4648
|
+
if (nCode >= 0 && visible)
|
|
4649
|
+
{
|
|
4650
|
+
int msg = wParam.ToInt32();
|
|
4651
|
+
// Deliberately ignore WM_MOUSEMOVE (0x0200): nudging the mouse never triggers takeover.
|
|
4652
|
+
bool isClick = msg == 0x0201 || msg == 0x0204 || msg == 0x0207;
|
|
4653
|
+
bool isWheel = msg == 0x020A || msg == 0x020E;
|
|
4654
|
+
if (isClick || isWheel)
|
|
4655
|
+
{
|
|
4656
|
+
var ms = (Native.MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(Native.MSLLHOOKSTRUCT));
|
|
4657
|
+
// Ignore synthetic clicks injected by our own SendInput (LLMHF_INJECTED = 0x01, lower IL = 0x02).
|
|
4658
|
+
if ((ms.flags & 0x03) == 0 && ms.dwExtraInfo != Native.Marker && !IsOnOwnUi(ms.pt.X, ms.pt.Y))
|
|
4659
|
+
{
|
|
4660
|
+
int now = Environment.TickCount;
|
|
4661
|
+
lastTyping = now;
|
|
4662
|
+
if (isClick)
|
|
4663
|
+
{
|
|
4664
|
+
string button = msg == 0x0204 ? "right" : msg == 0x0207 ? "middle" : "left";
|
|
4665
|
+
string kind = "click";
|
|
4666
|
+
lock (UserActionLock)
|
|
4667
|
+
{
|
|
4668
|
+
if (button == "left" && unchecked(now - lastClickTick) <= 500
|
|
4669
|
+
&& Math.Abs(ms.pt.X - lastClickX) <= 6 && Math.Abs(ms.pt.Y - lastClickY) <= 6)
|
|
4670
|
+
{
|
|
4671
|
+
kind = "double_click";
|
|
4672
|
+
lastClickTick = int.MinValue / 2;
|
|
4673
|
+
}
|
|
4674
|
+
else
|
|
4675
|
+
{
|
|
4676
|
+
lastClickTick = now;
|
|
4677
|
+
lastClickX = ms.pt.X;
|
|
4678
|
+
lastClickY = ms.pt.Y;
|
|
4679
|
+
}
|
|
4680
|
+
}
|
|
4681
|
+
RecordUserMouseAsync(kind, button, "", ms.pt.X, ms.pt.Y);
|
|
4682
|
+
}
|
|
4683
|
+
else
|
|
4684
|
+
{
|
|
4685
|
+
bool shouldEmit = false;
|
|
4686
|
+
lock (UserActionLock)
|
|
4687
|
+
{
|
|
4688
|
+
if (unchecked(now - lastScrollTick) > 600) { lastScrollTick = now; shouldEmit = true; }
|
|
4689
|
+
}
|
|
4690
|
+
if (shouldEmit)
|
|
4691
|
+
{
|
|
4692
|
+
short delta = (short)((ms.mouseData >> 16) & 0xFFFF);
|
|
4693
|
+
string dir = msg == 0x020E ? (delta >= 0 ? "right" : "left") : (delta >= 0 ? "up" : "down");
|
|
4694
|
+
RecordUserMouseAsync("scroll", "", dir, ms.pt.X, ms.pt.Y);
|
|
4695
|
+
}
|
|
4696
|
+
}
|
|
4697
|
+
}
|
|
4698
|
+
}
|
|
4699
|
+
}
|
|
4700
|
+
return Native.CallNextHookEx(mouseHook, nCode, wParam, lParam);
|
|
3941
4701
|
}
|
|
3942
4702
|
|
|
3943
4703
|
static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
|
|
@@ -3968,6 +4728,18 @@ namespace DshComputerUse
|
|
|
3968
4728
|
int now = Environment.TickCount;
|
|
3969
4729
|
lastTyping = now;
|
|
3970
4730
|
if (unchecked(now - lastEmit) > 250) { lastEmit = now; Program.EmitEvent("user_input", "vk=0x" + vk.ToString("X2")); }
|
|
4731
|
+
int emitCount = 0;
|
|
4732
|
+
lock (UserActionLock)
|
|
4733
|
+
{
|
|
4734
|
+
keyBurstCount++;
|
|
4735
|
+
if (unchecked(now - lastKeySummaryTick) > 900)
|
|
4736
|
+
{
|
|
4737
|
+
lastKeySummaryTick = now;
|
|
4738
|
+
emitCount = keyBurstCount;
|
|
4739
|
+
keyBurstCount = 0;
|
|
4740
|
+
}
|
|
4741
|
+
}
|
|
4742
|
+
if (emitCount > 0) RecordUserKeyAsync(emitCount);
|
|
3971
4743
|
}
|
|
3972
4744
|
}
|
|
3973
4745
|
}
|