@copylee/dsh-computer-use 0.1.2 → 0.1.4
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 +10 -7
- package/helper/CuHelper.cs +180 -58
- package/helper/deepseek-white.png +0 -0
- package/lib/client.js +758 -0
- package/lib/index.js +271 -91
- package/lib/types/client/index.d.ts +39 -0
- package/lib/types/client/select.d.ts +17 -0
- package/lib/types/computer.d.ts +2 -2
- package/lib/types/helper-client.d.ts +2 -1
- package/lib/types/index.d.ts +4 -3
- package/lib/types/overlay.d.ts +39 -10
- package/lib/types/routes.d.ts +29 -0
- package/lib/types/settings.d.ts +11 -0
- package/package.json +25 -3
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@copylee/dsh-computer-use)
|
|
4
4
|
|
|
5
|
-
让 DeepSeek Harness 直接操控你的 Windows 电脑:看屏幕、点鼠标、敲键盘,打开应用、切换窗口、读写剪贴板。控制期间屏幕四周会泛起**橙色光晕**,顶部出现“**DeepSeek
|
|
5
|
+
让 DeepSeek Harness 直接操控你的 Windows 电脑:看屏幕、点鼠标、敲键盘,打开应用、切换窗口、读写剪贴板。控制期间屏幕四周会泛起**橙色光晕**,顶部出现“**DeepSeek Harness 正在操控你的电脑**”提示条,DeepSeek Harness 自己缩成右下角的置顶悬浮卡片,让你同时看到操作过程和 AI 的输出。按 **Esc** 暂停 / 继续,点“停止”结束本轮。
|
|
6
6
|
|
|
7
7
|
| 功能 | 说明 |
|
|
8
8
|
|---|---|
|
|
@@ -11,9 +11,12 @@
|
|
|
11
11
|
| 批量动作 | `computer_batch` 一次执行“点输入框 → 输入 → 回车”等多步,最后只截一张图 |
|
|
12
12
|
| 按应用授权 | 先 `request_access` 列出要操控的应用,经 DSH 原生审批后才能操作;也可改为“全部允许” |
|
|
13
13
|
| 不会操作自己 | 永远拒绝向 DeepSeek Harness 自身窗口输入;常见密码管理器默认禁止,可再自定义禁用列表 |
|
|
14
|
-
| 正在控制的提示 | 橙色光晕 +
|
|
14
|
+
| 正在控制的提示 | 橙色光晕 + 胶囊提示条(显示当前动作),**不会出现在截图里** |
|
|
15
|
+
| 悬浮卡片 | 操控期间 DeepSeek Harness 窗口缩成右下角置顶卡片,结束后自动恢复原尺寸、位置和最大化 / 最小化状态(也可选最小化或不动) |
|
|
16
|
+
| 暂停与停止 | 你亲手按 **Esc** 暂停(AI 停在下一步之前),再按 Esc 或点“继续”恢复,对话不会被中断;点“停止”才结束本轮。插件自己发出的 Esc 不会误触发 |
|
|
15
17
|
| 你随时可以插手 | 你用键盘打字时 AI 自动暂停,停手 1.5 秒后继续;你切换或打开了别的窗口,AI 下一步不会盲目执行,而是先看新截图再决定。鼠标移动不会触发,避免误触 |
|
|
16
|
-
| 中文输入 | Unicode
|
|
18
|
+
| 中文输入 | Unicode 直接输入,不受输入法状态影响;长文本走剪贴板并自动恢复原剪贴板;剪贴板文本统一为 CRLF,粘贴到 Obsidian 等应用不丢换行 |
|
|
19
|
+
| 打开应用 | `open_application` 同时搜索开始菜单和桌面快捷方式(含公共桌面),便携软件也能按名字打开 |
|
|
17
20
|
| 看不见图的模型 | `ui_elements` 用 Windows UI Automation 列出可点击元素和坐标,纯文本模型也能用 |
|
|
18
21
|
| 零原生依赖 | 首次使用时用 Windows 自带的 .NET Framework `csc.exe` 编译一个小 helper(约 1 秒,之后缓存),不需要 node-gyp、不受 Electron ABI 影响 |
|
|
19
22
|
|
|
@@ -41,7 +44,7 @@ dsh plugin --profile web add @copylee/dsh-computer-use@latest
|
|
|
41
44
|
|
|
42
45
|
按应用授权模式下,模型会先请求操控对应应用,你在 DSH 里批准即可。会话权限为“完全权限”或“自动审查”(不弹审批)时,请求会被自动批准,但 DeepSeek Harness 自身和禁用列表里的应用仍然不可操作。
|
|
43
46
|
|
|
44
|
-
**随时按 Esc
|
|
47
|
+
**随时按 Esc 暂停**,再按一次继续;点提示条上的“停止”结束本轮。想临时帮一把也可以直接上手:打字时提示条显示“你正在操作,已暂停”,AI 会等你停手;切到别的窗口后 AI 会先重新看屏幕。
|
|
45
48
|
|
|
46
49
|
## Agent 工具
|
|
47
50
|
|
|
@@ -58,14 +61,14 @@ dsh plugin --profile web add @copylee/dsh-computer-use@latest
|
|
|
58
61
|
|
|
59
62
|
## 设置
|
|
60
63
|
|
|
61
|
-
在 **设置 →
|
|
64
|
+
在 **设置 → 电脑控制** 中修改,保存后下一步操作即生效。页面上还能看到运行状态(屏幕分辨率、缩放比例和实际发给模型的截图尺寸),并可点“预览效果”看 3 秒光晕和提示条:
|
|
62
65
|
|
|
63
66
|
| 选项 | 默认 | 说明 |
|
|
64
67
|
|---|---|---|
|
|
65
68
|
| 授权方式 | 按应用授权 | 或“全部允许” |
|
|
66
69
|
| 光晕与提示条 | 开 | 控制时显示橙色边框和提示条 |
|
|
67
|
-
| 提示条名称 | DeepSeek | 显示为“<名称>
|
|
68
|
-
|
|
|
70
|
+
| 提示条名称 | DeepSeek Harness | 显示为“<名称> 正在操控你的电脑” |
|
|
71
|
+
| 操控期间 DSH 窗口 | 悬浮卡片 | 悬浮卡片 / 最小化 / 保持不变,结束后自动恢复 |
|
|
69
72
|
| 操作后自动截图 | 开 | 关闭可省 token,但模型需要自己截图 |
|
|
70
73
|
| 等待稳定 | 400 ms | 动作后多久再截图 |
|
|
71
74
|
| 截图最长边 / 总像素 / JPEG 质量 | 1366 / 1.15MP / 80 | 越大越清晰、越费 token |
|
package/helper/CuHelper.cs
CHANGED
|
@@ -92,6 +92,10 @@ namespace DshComputerUse
|
|
|
92
92
|
[DllImport("user32.dll")] public static extern IntPtr GetAncestor(IntPtr hwnd, uint flags);
|
|
93
93
|
[DllImport("user32.dll")] public static extern bool SetWindowPos(IntPtr hwnd, IntPtr after, int x, int y, int w, int h, uint flags);
|
|
94
94
|
[DllImport("user32.dll")] public static extern bool GetWindowRect(IntPtr hwnd, out RECT r);
|
|
95
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
96
|
+
public struct WINDOWPLACEMENT { public int length; public int flags; public int showCmd; public POINT ptMinPosition; public POINT ptMaxPosition; public RECT rcNormalPosition; }
|
|
97
|
+
[DllImport("user32.dll")] public static extern bool GetWindowPlacement(IntPtr hwnd, ref WINDOWPLACEMENT wp);
|
|
98
|
+
[DllImport("user32.dll")] public static extern bool SetWindowPlacement(IntPtr hwnd, ref WINDOWPLACEMENT wp);
|
|
95
99
|
[DllImport("dwmapi.dll")] public static extern int DwmGetWindowAttribute(IntPtr hwnd, int attr, out RECT value, int size);
|
|
96
100
|
[DllImport("dwmapi.dll")] public static extern int DwmGetWindowAttribute(IntPtr hwnd, int attr, out int value, int size);
|
|
97
101
|
|
|
@@ -266,7 +270,10 @@ namespace DshComputerUse
|
|
|
266
270
|
case "clipboard_get": { var d = new Dictionary<string, object>(); d["text"] = Clip.Get(); return d; }
|
|
267
271
|
case "clipboard_set": Clip.Set(Args.Str(r, "text", "")); return null;
|
|
268
272
|
case "ui": return Uia.Elements(r);
|
|
269
|
-
case "overlay_show": Overlay.ExcludeFromCapture = Args.Bool(r, "excludeFromCapture", true); Overlay.Show(
|
|
273
|
+
case "overlay_show": Overlay.ExcludeFromCapture = Args.Bool(r, "excludeFromCapture", true); Overlay.Show(r); return null;
|
|
274
|
+
case "overlay_pause": Overlay.SetPaused(Args.Bool(r, "paused", false)); return null;
|
|
275
|
+
case "window_card": 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));
|
|
276
|
+
case "window_uncard": return Windows.Uncard(new IntPtr(Convert.ToInt64(r["hwnd"])));
|
|
270
277
|
case "overlay_status": Overlay.Status(Args.Str(r, "status", "")); return null;
|
|
271
278
|
case "overlay_hide": Overlay.Hide(); return null;
|
|
272
279
|
default: throw new Exception("unknown command: " + cmd);
|
|
@@ -566,6 +573,7 @@ namespace DshComputerUse
|
|
|
566
573
|
|
|
567
574
|
public static void Set(string text)
|
|
568
575
|
{
|
|
576
|
+
if (!string.IsNullOrEmpty(text)) text = text.Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", "\r\n");
|
|
569
577
|
for (int i = 0; i < 5; i++)
|
|
570
578
|
{
|
|
571
579
|
try
|
|
@@ -716,6 +724,51 @@ namespace DshComputerUse
|
|
|
716
724
|
return d;
|
|
717
725
|
}
|
|
718
726
|
|
|
727
|
+
static readonly Dictionary<long, Native.WINDOWPLACEMENT> cards = new Dictionary<long, Native.WINDOWPLACEMENT>();
|
|
728
|
+
|
|
729
|
+
/// Shrink a window into an always-on-top card; Uncard restores it exactly.
|
|
730
|
+
public static object Card(IntPtr hwnd, int x, int y, int w, int h)
|
|
731
|
+
{
|
|
732
|
+
if (!Native.IsWindow(hwnd)) throw new Exception("window no longer exists");
|
|
733
|
+
if (!cards.ContainsKey(hwnd.ToInt64()))
|
|
734
|
+
{
|
|
735
|
+
var wp = new Native.WINDOWPLACEMENT();
|
|
736
|
+
wp.length = Marshal.SizeOf(typeof(Native.WINDOWPLACEMENT));
|
|
737
|
+
Native.GetWindowPlacement(hwnd, ref wp);
|
|
738
|
+
cards[hwnd.ToInt64()] = wp;
|
|
739
|
+
}
|
|
740
|
+
// A minimized window restores to its previous state, which may be maximized: restore until normal.
|
|
741
|
+
for (int i = 0; i < 2 && (Native.IsIconic(hwnd) || Native.IsZoomed(hwnd)); i++) { Native.ShowWindow(hwnd, 9); Thread.Sleep(150); }
|
|
742
|
+
Native.SetWindowPos(hwnd, new IntPtr(-1), x, y, w, h, 0x0010 | 0x0040); // TOPMOST, NOACTIVATE | SHOWWINDOW
|
|
743
|
+
// Apps enforce a minimum size (Electron does): keep the card anchored bottom-right.
|
|
744
|
+
Native.RECT rc;
|
|
745
|
+
if (Native.GetWindowRect(hwnd, out rc) && (rc.Right - rc.Left != w || rc.Bottom - rc.Top != h))
|
|
746
|
+
{
|
|
747
|
+
int nx = x + w - (rc.Right - rc.Left), ny = y + h - (rc.Bottom - rc.Top);
|
|
748
|
+
Native.SetWindowPos(hwnd, new IntPtr(-1), nx, ny, 0, 0, 0x0001 | 0x0010); // NOSIZE | NOACTIVATE
|
|
749
|
+
}
|
|
750
|
+
return Describe(hwnd);
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
public static object Uncard(IntPtr hwnd)
|
|
754
|
+
{
|
|
755
|
+
Native.WINDOWPLACEMENT wp;
|
|
756
|
+
bool known = cards.TryGetValue(hwnd.ToInt64(), out wp);
|
|
757
|
+
cards.Remove(hwnd.ToInt64());
|
|
758
|
+
if (!Native.IsWindow(hwnd)) return null;
|
|
759
|
+
Native.SetWindowPos(hwnd, new IntPtr(-2), 0, 0, 0, 0, 0x0001 | 0x0002 | 0x0010); // NOTOPMOST
|
|
760
|
+
if (known)
|
|
761
|
+
{
|
|
762
|
+
// Restore the normal rectangle first, then the original show state (maximized etc.).
|
|
763
|
+
int show = wp.showCmd;
|
|
764
|
+
wp.showCmd = 1; // SW_SHOWNORMAL
|
|
765
|
+
Native.SetWindowPlacement(hwnd, ref wp);
|
|
766
|
+
if (show == 3) Native.ShowWindow(hwnd, 3);
|
|
767
|
+
else if (show == 2) Native.ShowWindow(hwnd, 6);
|
|
768
|
+
}
|
|
769
|
+
return Describe(hwnd);
|
|
770
|
+
}
|
|
771
|
+
|
|
719
772
|
public static object Command(IntPtr hwnd, string op)
|
|
720
773
|
{
|
|
721
774
|
if (!Native.IsWindow(hwnd)) throw new Exception("window no longer exists");
|
|
@@ -753,6 +806,17 @@ namespace DshComputerUse
|
|
|
753
806
|
}
|
|
754
807
|
}
|
|
755
808
|
finally { Marshal.FinalReleaseComObject(shell); }
|
|
809
|
+
// Desktop shortcuts too: portable apps often only live there.
|
|
810
|
+
foreach (var folder in new[] { Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory) })
|
|
811
|
+
{
|
|
812
|
+
try
|
|
813
|
+
{
|
|
814
|
+
if (folder.Length == 0 || !Directory.Exists(folder)) continue;
|
|
815
|
+
foreach (var f in Directory.GetFiles(folder, "*.lnk"))
|
|
816
|
+
list.Add(new KeyValuePair<string, string>(Path.GetFileNameWithoutExtension(f), "lnk:" + f));
|
|
817
|
+
}
|
|
818
|
+
catch (Exception) { }
|
|
819
|
+
}
|
|
756
820
|
cache = list; cachedAt = DateTime.UtcNow;
|
|
757
821
|
return list;
|
|
758
822
|
}
|
|
@@ -785,7 +849,8 @@ namespace DshComputerUse
|
|
|
785
849
|
string target = Args.Str(r, "target", "");
|
|
786
850
|
string args = Args.Str(r, "args", "");
|
|
787
851
|
ProcessStartInfo psi;
|
|
788
|
-
if (appId.
|
|
852
|
+
if (appId.StartsWith("lnk:")) psi = new ProcessStartInfo(appId.Substring(4));
|
|
853
|
+
else if (appId.Length > 0) psi = new ProcessStartInfo("explorer.exe", "shell:AppsFolder\\" + appId);
|
|
789
854
|
else { psi = new ProcessStartInfo(target); if (args.Length > 0) psi.Arguments = args; }
|
|
790
855
|
psi.UseShellExecute = true;
|
|
791
856
|
using (var p = Process.Start(psi)) { }
|
|
@@ -958,15 +1023,21 @@ namespace DshComputerUse
|
|
|
958
1023
|
static Control invoker;
|
|
959
1024
|
static readonly List<LayeredForm> glows = new List<LayeredForm>();
|
|
960
1025
|
static LayeredForm pill;
|
|
961
|
-
static Rectangle pillRect
|
|
1026
|
+
static Rectangle pillRect;
|
|
1027
|
+
static readonly List<KeyValuePair<Rectangle, string>> buttons = new List<KeyValuePair<Rectangle, string>>();
|
|
962
1028
|
static bool pillAtBottom;
|
|
963
|
-
static string label = "", status = "";
|
|
964
|
-
static
|
|
1029
|
+
static string label = "", status = "", rendered = "";
|
|
1030
|
+
static Image icon;
|
|
1031
|
+
static string iconPath = "";
|
|
1032
|
+
static int idleMs = 1500;
|
|
965
1033
|
static System.Windows.Forms.Timer timer;
|
|
966
1034
|
static DateTime shownAt;
|
|
967
1035
|
static IntPtr hook = IntPtr.Zero;
|
|
968
1036
|
static Native.LowLevelKeyboardProc hookProc;
|
|
969
1037
|
static volatile bool visible;
|
|
1038
|
+
static volatile bool paused;
|
|
1039
|
+
static int lastTyping = int.MinValue / 2;
|
|
1040
|
+
static int lastEmit;
|
|
970
1041
|
static readonly object RectLock = new object();
|
|
971
1042
|
|
|
972
1043
|
static void Ensure()
|
|
@@ -991,17 +1062,32 @@ namespace DshComputerUse
|
|
|
991
1062
|
|
|
992
1063
|
static void Ui(MethodInvoker action) { invoker.Invoke(action); }
|
|
993
1064
|
|
|
994
|
-
public static void Show(string
|
|
1065
|
+
public static void Show(Dictionary<string, object> r)
|
|
995
1066
|
{
|
|
996
1067
|
Ensure();
|
|
997
1068
|
Ui(delegate
|
|
998
1069
|
{
|
|
999
|
-
label =
|
|
1070
|
+
label = Args.Str(r, "label", "");
|
|
1071
|
+
status = Args.Str(r, "status", "");
|
|
1072
|
+
idleMs = Args.Int(r, "idleMs", 1500);
|
|
1073
|
+
string path = Args.Str(r, "icon", "");
|
|
1074
|
+
if (path != iconPath)
|
|
1075
|
+
{
|
|
1076
|
+
iconPath = path;
|
|
1077
|
+
if (icon != null) { icon.Dispose(); icon = null; }
|
|
1078
|
+
try
|
|
1079
|
+
{
|
|
1080
|
+
if (path.Length > 0 && File.Exists(path))
|
|
1081
|
+
using (var raw = Image.FromFile(path)) icon = new Bitmap(raw);
|
|
1082
|
+
}
|
|
1083
|
+
catch (Exception) { icon = null; }
|
|
1084
|
+
}
|
|
1000
1085
|
if (visible) { RenderPill(); return; }
|
|
1001
1086
|
pillAtBottom = false;
|
|
1087
|
+
paused = false;
|
|
1002
1088
|
foreach (var g in glows) g.Close();
|
|
1003
1089
|
glows.Clear();
|
|
1004
|
-
if (glow)
|
|
1090
|
+
if (Args.Bool(r, "glow", true))
|
|
1005
1091
|
{
|
|
1006
1092
|
foreach (Dictionary<string, object> d in Screen2.Displays())
|
|
1007
1093
|
{
|
|
@@ -1017,7 +1103,8 @@ namespace DshComputerUse
|
|
|
1017
1103
|
pill = new LayeredForm(false);
|
|
1018
1104
|
pill.MouseUp += delegate (object s, MouseEventArgs e)
|
|
1019
1105
|
{
|
|
1020
|
-
|
|
1106
|
+
foreach (var b in buttons)
|
|
1107
|
+
if (b.Key.Contains(e.Location)) { Press(b.Value); break; }
|
|
1021
1108
|
};
|
|
1022
1109
|
pill.Show();
|
|
1023
1110
|
}
|
|
@@ -1035,16 +1122,24 @@ namespace DshComputerUse
|
|
|
1035
1122
|
Ui(delegate { status = newStatus; RenderPill(); });
|
|
1036
1123
|
}
|
|
1037
1124
|
|
|
1125
|
+
public static void SetPaused(bool value)
|
|
1126
|
+
{
|
|
1127
|
+
if (thread == null) return;
|
|
1128
|
+
Ui(delegate { paused = value; RenderPill(); });
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1038
1131
|
public static void Hide()
|
|
1039
1132
|
{
|
|
1040
1133
|
if (thread == null) return;
|
|
1041
1134
|
Ui(delegate
|
|
1042
1135
|
{
|
|
1043
1136
|
visible = false;
|
|
1137
|
+
paused = false;
|
|
1044
1138
|
timer.Stop();
|
|
1045
1139
|
foreach (var g in glows) g.Close();
|
|
1046
1140
|
glows.Clear();
|
|
1047
1141
|
if (pill != null) { pill.Close(); pill = null; }
|
|
1142
|
+
rendered = "";
|
|
1048
1143
|
lock (RectLock) pillRect = Rectangle.Empty;
|
|
1049
1144
|
RemoveHook();
|
|
1050
1145
|
});
|
|
@@ -1069,14 +1164,26 @@ namespace DshComputerUse
|
|
|
1069
1164
|
Thread.Sleep(30);
|
|
1070
1165
|
}
|
|
1071
1166
|
|
|
1167
|
+
// pause / resume / stop, from Esc or the pill buttons.
|
|
1168
|
+
static void Press(string action)
|
|
1169
|
+
{
|
|
1170
|
+
if (action == "stop") { paused = false; Program.EmitEvent("stop", "button"); }
|
|
1171
|
+
else if (action == "pause") { paused = true; Program.EmitEvent("pause", "user"); }
|
|
1172
|
+
else if (action == "resume") { paused = false; Program.EmitEvent("resume", "user"); }
|
|
1173
|
+
RenderPill();
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
static bool Typing() { return unchecked(Environment.TickCount - lastTyping) < idleMs; }
|
|
1177
|
+
|
|
1072
1178
|
static void Tick()
|
|
1073
1179
|
{
|
|
1074
1180
|
if (!visible) return;
|
|
1075
1181
|
double t = (DateTime.UtcNow - shownAt).TotalSeconds;
|
|
1076
1182
|
double fadeIn = Math.Min(1.0, t / 0.35);
|
|
1077
|
-
double breathe = 0.72 + 0.28 * (0.5 + 0.5 * Math.Sin(t * Math.PI * 2 / 2.6));
|
|
1183
|
+
double breathe = paused ? 0.55 : 0.72 + 0.28 * (0.5 + 0.5 * Math.Sin(t * Math.PI * 2 / 2.6));
|
|
1078
1184
|
byte alpha = (byte)Math.Max(0, Math.Min(255, 255 * fadeIn * breathe));
|
|
1079
1185
|
foreach (var g in glows) g.SetAlpha(alpha);
|
|
1186
|
+
if (Key() != rendered) RenderPill(); // typing started or stopped
|
|
1080
1187
|
if ((int)(t * 25) % 50 == 0)
|
|
1081
1188
|
{
|
|
1082
1189
|
foreach (var g in glows) g.KeepOnTop();
|
|
@@ -1121,31 +1228,25 @@ namespace DshComputerUse
|
|
|
1121
1228
|
return p;
|
|
1122
1229
|
}
|
|
1123
1230
|
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
/// A whale facing left, drawn in a 24x24 design box scaled to `size`.
|
|
1127
|
-
static void DrawWhale(Graphics g, float x, float y, float size, Color eye)
|
|
1231
|
+
// What the pill should say right now; it is re-rendered whenever this changes.
|
|
1232
|
+
static void Content(out string main, out string sub, out string[] actions, out string[] captions)
|
|
1128
1233
|
{
|
|
1129
|
-
|
|
1130
|
-
Func<float, float, PointF> P = delegate (float px, float py) { return new PointF(x + px * k, y + py * k); };
|
|
1131
|
-
using (var path = new GraphicsPath())
|
|
1234
|
+
if (paused)
|
|
1132
1235
|
{
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
path.AddBezier(P(19.2f, 3.5f), P(21.5f, 4.5f), P(23f, 3.8f), P(23.5f, 2.5f));
|
|
1137
|
-
path.AddBezier(P(23.5f, 2.5f), P(23.8f, 6f), P(22.5f, 9.5f), P(19.5f, 13f));
|
|
1138
|
-
path.AddBezier(P(19.5f, 13f), P(17.5f, 17.5f), P(13f, 19.5f), P(8.5f, 19.3f));
|
|
1139
|
-
path.AddBezier(P(8.5f, 19.3f), P(4f, 19f), P(1f, 17.5f), P(1f, 14f));
|
|
1140
|
-
path.CloseFigure();
|
|
1141
|
-
using (var brush = new SolidBrush(Whale)) g.FillPath(brush, path);
|
|
1236
|
+
main = "已暂停"; sub = "按 Esc 继续";
|
|
1237
|
+
actions = new[] { "resume", "stop" }; captions = new[] { "继续", "停止" };
|
|
1238
|
+
return;
|
|
1142
1239
|
}
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1240
|
+
main = label;
|
|
1241
|
+
sub = Typing() ? "你正在操作,已暂停" : status.Length > 0 ? status : "Esc 暂停";
|
|
1242
|
+
actions = new[] { "stop" }; captions = new[] { "停止" };
|
|
1243
|
+
}
|
|
1244
|
+
|
|
1245
|
+
static string Key()
|
|
1246
|
+
{
|
|
1247
|
+
string main, sub; string[] actions, captions;
|
|
1248
|
+
Content(out main, out sub, out actions, out captions);
|
|
1249
|
+
return main + "|" + sub + "|" + string.Join(",", actions) + "|" + pillAtBottom;
|
|
1149
1250
|
}
|
|
1150
1251
|
|
|
1151
1252
|
static void RenderPill()
|
|
@@ -1161,10 +1262,11 @@ namespace DshComputerUse
|
|
|
1161
1262
|
scale = (int)d["dpi"] / 96f;
|
|
1162
1263
|
}
|
|
1163
1264
|
}
|
|
1164
|
-
|
|
1265
|
+
string main, sub; string[] actions, captions;
|
|
1266
|
+
Content(out main, out sub, out actions, out captions);
|
|
1267
|
+
rendered = Key();
|
|
1268
|
+
if (sub.Length > 48) sub = sub.Substring(0, 47) + "…";
|
|
1165
1269
|
|
|
1166
|
-
string main = label;
|
|
1167
|
-
string hint = "Esc 停止";
|
|
1168
1270
|
float px = 1.333f * scale; // points -> physical pixels
|
|
1169
1271
|
using (var fMain = new Font("Microsoft YaHei UI", 10f * px, FontStyle.Bold, GraphicsUnit.Pixel))
|
|
1170
1272
|
using (var fSub = new Font("Microsoft YaHei UI", 9f * px, FontStyle.Regular, GraphicsUnit.Pixel))
|
|
@@ -1175,15 +1277,18 @@ namespace DshComputerUse
|
|
|
1175
1277
|
mg.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
|
|
1176
1278
|
var fmt = StringFormat.GenericTypographic;
|
|
1177
1279
|
fmt.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces;
|
|
1178
|
-
string sub = status.Length > 0 ? status : hint;
|
|
1179
|
-
if (sub.Length > 48) sub = sub.Substring(0, 47) + "…";
|
|
1180
1280
|
SizeF mainSize = mg.MeasureString(main, fMain, 10000, fmt);
|
|
1181
1281
|
SizeF subSize = mg.MeasureString(sub, fSub, 10000, fmt);
|
|
1182
|
-
|
|
1183
|
-
float
|
|
1184
|
-
|
|
1185
|
-
float
|
|
1186
|
-
|
|
1282
|
+
float pad = 14 * scale, gap = 11 * scale, iconSize = 24 * scale;
|
|
1283
|
+
float height = 40 * scale, btnH = 26 * scale, btnGap = 6 * scale;
|
|
1284
|
+
var btnSizes = new SizeF[captions.Length];
|
|
1285
|
+
float btnsW = 0;
|
|
1286
|
+
for (int i = 0; i < captions.Length; i++)
|
|
1287
|
+
{
|
|
1288
|
+
btnSizes[i] = mg.MeasureString(captions[i], fBtn, 10000, fmt);
|
|
1289
|
+
btnsW += btnSizes[i].Width + 22 * scale + (i > 0 ? btnGap : 0);
|
|
1290
|
+
}
|
|
1291
|
+
float width = pad + iconSize + gap + mainSize.Width + gap + 1 * scale + gap + subSize.Width + gap + btnsW + (pad - 7 * scale);
|
|
1187
1292
|
int W = (int)Math.Ceiling(width), H = (int)Math.Ceiling(height);
|
|
1188
1293
|
int x = work.X + (work.Width - W) / 2;
|
|
1189
1294
|
int y = pillAtBottom ? work.Bottom - H - (int)(18 * scale) : work.Y + (int)(14 * scale);
|
|
@@ -1193,6 +1298,7 @@ namespace DshComputerUse
|
|
|
1193
1298
|
{
|
|
1194
1299
|
g.Clear(Color.Transparent);
|
|
1195
1300
|
g.SmoothingMode = SmoothingMode.AntiAlias;
|
|
1301
|
+
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
|
1196
1302
|
g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
|
|
1197
1303
|
var body = new RectangleF(0.5f, 0.5f, W - 1, H - 1);
|
|
1198
1304
|
using (var path = Rounded(body, (H - 1) / 2f))
|
|
@@ -1200,19 +1306,28 @@ namespace DshComputerUse
|
|
|
1200
1306
|
using (var brush = new SolidBrush(Color.FromArgb(242, 31, 30, 29))) g.FillPath(brush, path);
|
|
1201
1307
|
using (var pen = new Pen(Color.FromArgb(200, Accent), Math.Max(1f, 1.2f * scale))) g.DrawPath(pen, path);
|
|
1202
1308
|
}
|
|
1203
|
-
|
|
1204
|
-
|
|
1309
|
+
var iconRect = new RectangleF(pad, (H - iconSize) / 2f, iconSize, iconSize);
|
|
1310
|
+
if (icon != null) g.DrawImage(icon, iconRect);
|
|
1311
|
+
else using (var brush = new SolidBrush(Accent)) g.FillEllipse(brush, RectangleF.Inflate(iconRect, -5 * scale, -5 * scale));
|
|
1312
|
+
float tx = pad + iconSize + gap;
|
|
1205
1313
|
using (var b = new SolidBrush(Color.FromArgb(250, 250, 249))) g.DrawString(main, fMain, b, tx, (H - mainSize.Height) / 2f, fmt);
|
|
1206
1314
|
tx += mainSize.Width + gap;
|
|
1207
1315
|
using (var pen = new Pen(Color.FromArgb(90, 255, 255, 255), Math.Max(1f, scale))) g.DrawLine(pen, tx, H * 0.3f, tx, H * 0.7f);
|
|
1208
1316
|
tx += 1 * scale + gap;
|
|
1209
1317
|
using (var b = new SolidBrush(Color.FromArgb(175, 172, 168))) g.DrawString(sub, fSub, b, tx, (H - subSize.Height) / 2f, fmt);
|
|
1210
1318
|
tx += subSize.Width + gap;
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1319
|
+
buttons.Clear();
|
|
1320
|
+
for (int i = 0; i < captions.Length; i++)
|
|
1321
|
+
{
|
|
1322
|
+
float bw = btnSizes[i].Width + 22 * scale;
|
|
1323
|
+
var btn = new RectangleF(tx, (H - btnH) / 2f, bw, btnH);
|
|
1324
|
+
bool primary = i == 0;
|
|
1325
|
+
using (var path = Rounded(btn, btnH / 2f))
|
|
1326
|
+
using (var brush = new SolidBrush(primary ? Accent : Color.FromArgb(70, 68, 66))) g.FillPath(brush, path);
|
|
1327
|
+
using (var b = new SolidBrush(Color.White)) g.DrawString(captions[i], fBtn, b, btn.X + (bw - btnSizes[i].Width) / 2f, btn.Y + (btnH - btnSizes[i].Height) / 2f, fmt);
|
|
1328
|
+
buttons.Add(new KeyValuePair<Rectangle, string>(Rectangle.Round(btn), actions[i]));
|
|
1329
|
+
tx += bw + btnGap;
|
|
1330
|
+
}
|
|
1216
1331
|
pill.SetBitmap(bmp, new Rectangle(x, y, W, H), 255);
|
|
1217
1332
|
}
|
|
1218
1333
|
lock (RectLock) pillRect = new Rectangle(x, y, W, H);
|
|
@@ -1234,23 +1349,30 @@ namespace DshComputerUse
|
|
|
1234
1349
|
hook = IntPtr.Zero;
|
|
1235
1350
|
}
|
|
1236
1351
|
|
|
1237
|
-
static long lastTyping;
|
|
1238
|
-
|
|
1239
1352
|
static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
|
|
1240
1353
|
{
|
|
1241
|
-
if (nCode >= 0 && visible
|
|
1354
|
+
if (nCode >= 0 && visible)
|
|
1242
1355
|
{
|
|
1356
|
+
int msg = wParam.ToInt32();
|
|
1243
1357
|
var kb = (Native.KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(Native.KBDLLHOOKSTRUCT));
|
|
1244
1358
|
// Only physical keys count: our own SendInput sets LLKHF_INJECTED (0x10).
|
|
1245
1359
|
if ((kb.flags & 0x10) == 0)
|
|
1246
1360
|
{
|
|
1247
|
-
|
|
1248
|
-
|
|
1361
|
+
bool down = msg == 0x100 || msg == 0x104;
|
|
1362
|
+
if (kb.vkCode == 0x1B)
|
|
1363
|
+
{
|
|
1364
|
+
// Esc toggles pause and is swallowed, so the focused app
|
|
1365
|
+
// (DeepSeek Harness included) never turns it into "stop".
|
|
1366
|
+
if (down) invoker.BeginInvoke((MethodInvoker)delegate { Press(paused ? "resume" : "pause"); });
|
|
1367
|
+
return new IntPtr(1);
|
|
1368
|
+
}
|
|
1369
|
+
if (down)
|
|
1249
1370
|
{
|
|
1250
|
-
// The user is typing:
|
|
1251
|
-
//
|
|
1252
|
-
|
|
1253
|
-
|
|
1371
|
+
// The user is typing: the host waits. Mouse movement is
|
|
1372
|
+
// deliberately ignored (too easy to nudge).
|
|
1373
|
+
int now = Environment.TickCount;
|
|
1374
|
+
lastTyping = now;
|
|
1375
|
+
if (unchecked(now - lastEmit) > 250) { lastEmit = now; Program.EmitEvent("user_input", "keyboard"); }
|
|
1254
1376
|
}
|
|
1255
1377
|
}
|
|
1256
1378
|
}
|
|
Binary file
|