kotonebot 0.3.1__py3-none-any.whl → 0.5.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. kotonebot/__init__.py +39 -39
  2. kotonebot/backend/bot.py +312 -302
  3. kotonebot/backend/color.py +525 -525
  4. kotonebot/backend/context/__init__.py +3 -3
  5. kotonebot/backend/context/context.py +49 -56
  6. kotonebot/backend/context/task_action.py +183 -175
  7. kotonebot/backend/core.py +129 -126
  8. kotonebot/backend/debug/entry.py +89 -89
  9. kotonebot/backend/debug/mock.py +78 -78
  10. kotonebot/backend/debug/server.py +222 -222
  11. kotonebot/backend/debug/vars.py +351 -351
  12. kotonebot/backend/dispatch.py +227 -227
  13. kotonebot/backend/flow_controller.py +196 -196
  14. kotonebot/backend/loop.py +12 -88
  15. kotonebot/backend/ocr.py +535 -529
  16. kotonebot/backend/preprocessor.py +103 -103
  17. kotonebot/client/__init__.py +9 -9
  18. kotonebot/client/device.py +528 -502
  19. kotonebot/client/fast_screenshot.py +377 -377
  20. kotonebot/client/host/__init__.py +43 -12
  21. kotonebot/client/host/adb_common.py +107 -94
  22. kotonebot/client/host/custom.py +118 -114
  23. kotonebot/client/host/leidian_host.py +196 -201
  24. kotonebot/client/host/mumu12_host.py +353 -358
  25. kotonebot/client/host/protocol.py +214 -213
  26. kotonebot/client/host/windows_common.py +58 -55
  27. kotonebot/client/implements/__init__.py +71 -7
  28. kotonebot/client/implements/adb.py +89 -85
  29. kotonebot/client/implements/adb_raw.py +162 -158
  30. kotonebot/client/implements/nemu_ipc/__init__.py +11 -7
  31. kotonebot/client/implements/nemu_ipc/external_renderer_ipc.py +284 -284
  32. kotonebot/client/implements/nemu_ipc/nemu_ipc.py +327 -327
  33. kotonebot/client/implements/remote_windows.py +188 -192
  34. kotonebot/client/implements/uiautomator2.py +85 -81
  35. kotonebot/client/implements/windows.py +176 -168
  36. kotonebot/client/protocol.py +69 -69
  37. kotonebot/client/registration.py +24 -24
  38. kotonebot/config/base_config.py +96 -96
  39. kotonebot/config/manager.py +36 -36
  40. kotonebot/errors.py +76 -71
  41. kotonebot/interop/win/__init__.py +10 -0
  42. kotonebot/interop/win/_mouse.py +311 -0
  43. kotonebot/interop/win/message_box.py +313 -313
  44. kotonebot/interop/win/reg.py +37 -37
  45. kotonebot/interop/win/shortcut.py +43 -43
  46. kotonebot/interop/win/task_dialog.py +513 -469
  47. kotonebot/logging/__init__.py +2 -2
  48. kotonebot/logging/log.py +17 -17
  49. kotonebot/primitives/__init__.py +17 -17
  50. kotonebot/primitives/geometry.py +862 -290
  51. kotonebot/primitives/visual.py +63 -63
  52. kotonebot/tools/mirror.py +354 -354
  53. kotonebot/ui/file_host/sensio.py +36 -36
  54. kotonebot/ui/file_host/tmp_send.py +54 -54
  55. kotonebot/ui/pushkit/__init__.py +3 -3
  56. kotonebot/ui/pushkit/image_host.py +88 -87
  57. kotonebot/ui/pushkit/protocol.py +13 -13
  58. kotonebot/ui/pushkit/wxpusher.py +54 -53
  59. kotonebot/ui/user.py +148 -143
  60. kotonebot/util.py +436 -409
  61. {kotonebot-0.3.1.dist-info → kotonebot-0.5.0.dist-info}/METADATA +82 -76
  62. kotonebot-0.5.0.dist-info/RECORD +71 -0
  63. {kotonebot-0.3.1.dist-info → kotonebot-0.5.0.dist-info}/licenses/LICENSE +673 -673
  64. kotonebot-0.3.1.dist-info/RECORD +0 -70
  65. {kotonebot-0.3.1.dist-info → kotonebot-0.5.0.dist-info}/WHEEL +0 -0
  66. {kotonebot-0.3.1.dist-info → kotonebot-0.5.0.dist-info}/top_level.txt +0 -0
@@ -1,285 +1,285 @@
1
- import ctypes
2
- import logging
3
- import os
4
-
5
- logger = logging.getLogger(__name__)
6
-
7
-
8
- class NemuIpcIncompatible(RuntimeError):
9
- """MuMu12 IPC 环境不兼容或 DLL 加载失败"""
10
-
11
-
12
- class ExternalRendererIpc:
13
- r"""对 `external_renderer_ipc.dll` 的轻量封装。
14
-
15
- 该类仅处理 DLL 加载与原型声明,并提供带有类型提示的薄包装方法,
16
- 方便在其他模块中调用且保持类型安全。
17
- 传入参数为 MuMu 根目录(如 F:\Apps\Netease\MuMuPlayer-12.0)。
18
- """
19
-
20
- def __init__(self, mumu_root_folder: str):
21
- if os.name != "nt":
22
- raise NemuIpcIncompatible("ExternalRendererIpc only supports Windows.")
23
-
24
- self.lib = self.__load_dll(mumu_root_folder)
25
- self.raise_on_error: bool = True
26
- """是否在调用 DLL 函数失败时抛出异常。"""
27
- self.__declare_prototypes()
28
-
29
- def connect(self, nemu_folder: str, instance_id: int) -> int:
30
- """
31
- 建立连接。
32
-
33
- API 原型:
34
- `int nemu_connect(const wchar_t* path, int index)`
35
-
36
- :param nemu_folder: 模拟器安装路径。
37
- :param instance_id: 模拟器实例 ID。
38
- :return: 成功返回连接 ID,失败返回 0。
39
- """
40
- return self.lib.nemu_connect(nemu_folder, instance_id)
41
-
42
- def disconnect(self, connect_id: int) -> None:
43
- """
44
- 断开连接。
45
-
46
- API 原型:
47
- `void nemu_disconnect(int handle)`
48
-
49
- :param connect_id: 连接 ID。
50
- :return: 无返回值。
51
- """
52
- return self.lib.nemu_disconnect(connect_id)
53
-
54
- def get_display_id(self, connect_id: int, pkg: str, app_index: int) -> int:
55
- """
56
- 获取指定包的 display id。
57
-
58
- API 原型:
59
- `int nemu_get_display_id(int handle, const char* pkg, int appIndex)`
60
-
61
- :param connect_id: 连接 ID。
62
- :param pkg: 包名。
63
- :param app_index: 多开应用索引。
64
- :return: <0 表示失败,>=0 表示有效 display id。
65
- """
66
- return self.lib.nemu_get_display_id(connect_id, pkg.encode('utf-8'), app_index)
67
-
68
- def capture_display(
69
- self,
70
- connect_id: int,
71
- display_id: int,
72
- buf_len: int,
73
- width_ptr: ctypes.c_void_p,
74
- height_ptr: ctypes.c_void_p,
75
- buffer_ptr: ctypes.c_void_p,
76
- ) -> int:
77
- """
78
- 截取指定显示屏内容。
79
-
80
- API 原型:
81
- `int nemu_capture_display(int handle, unsigned int displayid, int buffer_size, int *width, int *height, unsigned char* pixels)`
82
-
83
- :param connect_id: 连接 ID。
84
- :param display_id: 显示屏 ID。
85
- :param buf_len: 缓冲区长度(字节)。
86
- :param width_ptr: 用于接收宽度的指针(ctypes.c_void_p/int 指针)。
87
- :param height_ptr: 用于接收高度的指针(ctypes.c_void_p/int 指针)。
88
- :param buffer_ptr: 用于接收像素数据的指针(ctypes.c_void_p/unsigned char* 指针)。
89
- :return: 0 表示成功,>0 表示失败。
90
- """
91
- return self.lib.nemu_capture_display(
92
- connect_id,
93
- display_id,
94
- buf_len,
95
- width_ptr,
96
- height_ptr,
97
- buffer_ptr,
98
- )
99
-
100
- def input_text(self, connect_id: int, text: str) -> int:
101
- """
102
- 输入文本。
103
-
104
- API 原型:
105
- `int nemu_input_text(int handle, int size, const char* buf)`
106
-
107
- :param connect_id: 连接 ID。
108
- :param text: 输入文本(utf-8)。
109
- :return: 0 表示成功,>0 表示失败。
110
- """
111
- buf = text.encode('utf-8')
112
- return self.lib.nemu_input_text(connect_id, len(buf), buf)
113
-
114
- def input_touch_down(self, connect_id: int, display_id: int, x: int, y: int) -> int:
115
- """
116
- 发送触摸按下事件。
117
-
118
- API 原型:
119
- `int nemu_input_event_touch_down(int handle, int displayid, int x_point, int y_point)`
120
-
121
- :param connect_id: 连接 ID。
122
- :param display_id: 显示屏 ID。
123
- :param x: 触摸点 X 坐标。
124
- :param y: 触摸点 Y 坐标。
125
- :return: 0 表示成功,>0 表示失败。
126
- """
127
- return self.lib.nemu_input_event_touch_down(connect_id, display_id, x, y)
128
-
129
- def input_touch_up(self, connect_id: int, display_id: int) -> int:
130
- """
131
- 发送触摸抬起事件。
132
-
133
- API 原型:
134
- `int nemu_input_event_touch_up(int handle, int displayid)`
135
-
136
- :param connect_id: 连接 ID。
137
- :param display_id: 显示屏 ID。
138
- :return: 0 表示成功,>0 表示失败。
139
- """
140
- return self.lib.nemu_input_event_touch_up(connect_id, display_id)
141
-
142
- def input_key_down(self, connect_id: int, display_id: int, key_code: int) -> int:
143
- """
144
- 发送按键按下事件。
145
-
146
- API 原型:
147
- `int nemu_input_event_key_down(int handle, int displayid, int key_code)`
148
-
149
- :param connect_id: 连接 ID。
150
- :param display_id: 显示屏 ID。
151
- :param key_code: 按键码。
152
- :return: 0 表示成功,>0 表示失败。
153
- """
154
- return self.lib.nemu_input_event_key_down(connect_id, display_id, key_code)
155
-
156
- def input_key_up(self, connect_id: int, display_id: int, key_code: int) -> int:
157
- """
158
- 发送按键抬起事件。
159
-
160
- API 原型:
161
- `int nemu_input_event_key_up(int handle, int displayid, int key_code)`
162
-
163
- :param connect_id: 连接 ID。
164
- :param display_id: 显示屏 ID。
165
- :param key_code: 按键码。
166
- :return: 0 表示成功,>0 表示失败。
167
- """
168
- return self.lib.nemu_input_event_key_up(connect_id, display_id, key_code)
169
-
170
- def input_finger_touch_down(self, connect_id: int, display_id: int, finger_id: int, x: int, y: int) -> int:
171
- """
172
- 多指触摸按下。
173
-
174
- API 原型:
175
- `int nemu_input_event_finger_touch_down(int handle, int displayid, int finger_id, int x_point, int y_point)`
176
-
177
- :param connect_id: 连接 ID。
178
- :param display_id: 显示屏 ID。
179
- :param finger_id: 手指编号(1-10)。
180
- :param x: 触摸点 X 坐标。
181
- :param y: 触摸点 Y 坐标。
182
- :return: 0 表示成功,>0 表示失败。
183
- """
184
- return self.lib.nemu_input_event_finger_touch_down(connect_id, display_id, finger_id, x, y)
185
-
186
- def input_finger_touch_up(self, connect_id: int, display_id: int, finger_id: int) -> int:
187
- """
188
- 多指触摸抬起。
189
-
190
- API 原型:
191
- `int nemu_input_event_finger_touch_up(int handle, int displayid, int slot_id)`
192
-
193
- :param connect_id: 连接 ID。
194
- :param display_id: 显示屏 ID。
195
- :param finger_id: 手指编号(1-10)。
196
- :return: 0 表示成功,>0 表示失败。
197
- """
198
- return self.lib.nemu_input_event_finger_touch_up(connect_id, display_id, finger_id)
199
-
200
- # ------------------------------------------------------------------
201
- # 内部工具
202
- # ------------------------------------------------------------------
203
-
204
- def __load_dll(self, mumu_root_folder: str) -> ctypes.CDLL:
205
- """尝试多条路径加载 DLL。传入为 MuMu 根目录。"""
206
- candidate_paths = [
207
- # <= 4.x
208
- os.path.join(mumu_root_folder, "shell", "sdk", "external_renderer_ipc.dll"),
209
- os.path.join(
210
- mumu_root_folder,
211
- "shell",
212
- "nx_device",
213
- "12.0",
214
- "sdk",
215
- "external_renderer_ipc.dll",
216
- ),
217
- # >= 5.x
218
- os.path.join(
219
- mumu_root_folder, "nx_device", "12.0", "shell", "sdk", "external_renderer_ipc.dll"
220
- ),
221
- ]
222
- for p in candidate_paths:
223
- if not os.path.exists(p):
224
- continue
225
- try:
226
- return ctypes.CDLL(p)
227
- except OSError as e: # pragma: no cover
228
- logger.warning("Failed to load DLL (%s): %s", p, e)
229
- raise NemuIpcIncompatible("external_renderer_ipc.dll not found or failed to load.")
230
-
231
- def __declare_prototypes(self) -> None:
232
- """声明 DLL 函数原型,确保 ctypes 类型安全。"""
233
- # 连接 / 断开
234
- self.lib.nemu_connect.argtypes = [ctypes.c_wchar_p, ctypes.c_int]
235
- self.lib.nemu_connect.restype = ctypes.c_int
236
-
237
- self.lib.nemu_disconnect.argtypes = [ctypes.c_int]
238
- self.lib.nemu_disconnect.restype = None
239
-
240
- # 获取 display id
241
- self.lib.nemu_get_display_id.argtypes = [ctypes.c_int, ctypes.c_char_p, ctypes.c_int]
242
- self.lib.nemu_get_display_id.restype = ctypes.c_int
243
-
244
- # 截图
245
- self.lib.nemu_capture_display.argtypes = [
246
- ctypes.c_int,
247
- ctypes.c_uint,
248
- ctypes.c_int,
249
- ctypes.c_void_p,
250
- ctypes.c_void_p,
251
- ctypes.c_void_p,
252
- ]
253
- self.lib.nemu_capture_display.restype = ctypes.c_int
254
-
255
- # 输入文本
256
- self.lib.nemu_input_text.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_char_p]
257
- self.lib.nemu_input_text.restype = ctypes.c_int
258
-
259
- # 触摸
260
- self.lib.nemu_input_event_touch_down.argtypes = [
261
- ctypes.c_int,
262
- ctypes.c_int,
263
- ctypes.c_int,
264
- ctypes.c_int,
265
- ]
266
- self.lib.nemu_input_event_touch_down.restype = ctypes.c_int
267
-
268
- self.lib.nemu_input_event_touch_up.argtypes = [ctypes.c_int, ctypes.c_int]
269
- self.lib.nemu_input_event_touch_up.restype = ctypes.c_int
270
-
271
- # 按键
272
- self.lib.nemu_input_event_key_down.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_int]
273
- self.lib.nemu_input_event_key_down.restype = ctypes.c_int
274
-
275
- self.lib.nemu_input_event_key_up.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_int]
276
- self.lib.nemu_input_event_key_up.restype = ctypes.c_int
277
-
278
- # 多指触摸
279
- self.lib.nemu_input_event_finger_touch_down.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int]
280
- self.lib.nemu_input_event_finger_touch_down.restype = ctypes.c_int
281
-
282
- self.lib.nemu_input_event_finger_touch_up.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_int]
283
- self.lib.nemu_input_event_finger_touch_up.restype = ctypes.c_int
284
-
1
+ import ctypes
2
+ import logging
3
+ import os
4
+
5
+ logger = logging.getLogger(__name__)
6
+
7
+
8
+ class NemuIpcIncompatible(RuntimeError):
9
+ """MuMu12 IPC 环境不兼容或 DLL 加载失败"""
10
+
11
+
12
+ class ExternalRendererIpc:
13
+ r"""对 `external_renderer_ipc.dll` 的轻量封装。
14
+
15
+ 该类仅处理 DLL 加载与原型声明,并提供带有类型提示的薄包装方法,
16
+ 方便在其他模块中调用且保持类型安全。
17
+ 传入参数为 MuMu 根目录(如 F:\Apps\Netease\MuMuPlayer-12.0)。
18
+ """
19
+
20
+ def __init__(self, mumu_root_folder: str):
21
+ if os.name != "nt":
22
+ raise NemuIpcIncompatible("ExternalRendererIpc only supports Windows.")
23
+
24
+ self.lib = self.__load_dll(mumu_root_folder)
25
+ self.raise_on_error: bool = True
26
+ """是否在调用 DLL 函数失败时抛出异常。"""
27
+ self.__declare_prototypes()
28
+
29
+ def connect(self, nemu_folder: str, instance_id: int) -> int:
30
+ """
31
+ 建立连接。
32
+
33
+ API 原型:
34
+ `int nemu_connect(const wchar_t* path, int index)`
35
+
36
+ :param nemu_folder: 模拟器安装路径。
37
+ :param instance_id: 模拟器实例 ID。
38
+ :return: 成功返回连接 ID,失败返回 0。
39
+ """
40
+ return self.lib.nemu_connect(nemu_folder, instance_id)
41
+
42
+ def disconnect(self, connect_id: int) -> None:
43
+ """
44
+ 断开连接。
45
+
46
+ API 原型:
47
+ `void nemu_disconnect(int handle)`
48
+
49
+ :param connect_id: 连接 ID。
50
+ :return: 无返回值。
51
+ """
52
+ return self.lib.nemu_disconnect(connect_id)
53
+
54
+ def get_display_id(self, connect_id: int, pkg: str, app_index: int) -> int:
55
+ """
56
+ 获取指定包的 display id。
57
+
58
+ API 原型:
59
+ `int nemu_get_display_id(int handle, const char* pkg, int appIndex)`
60
+
61
+ :param connect_id: 连接 ID。
62
+ :param pkg: 包名。
63
+ :param app_index: 多开应用索引。
64
+ :return: <0 表示失败,>=0 表示有效 display id。
65
+ """
66
+ return self.lib.nemu_get_display_id(connect_id, pkg.encode('utf-8'), app_index)
67
+
68
+ def capture_display(
69
+ self,
70
+ connect_id: int,
71
+ display_id: int,
72
+ buf_len: int,
73
+ width_ptr: ctypes.c_void_p,
74
+ height_ptr: ctypes.c_void_p,
75
+ buffer_ptr: ctypes.c_void_p,
76
+ ) -> int:
77
+ """
78
+ 截取指定显示屏内容。
79
+
80
+ API 原型:
81
+ `int nemu_capture_display(int handle, unsigned int displayid, int buffer_size, int *width, int *height, unsigned char* pixels)`
82
+
83
+ :param connect_id: 连接 ID。
84
+ :param display_id: 显示屏 ID。
85
+ :param buf_len: 缓冲区长度(字节)。
86
+ :param width_ptr: 用于接收宽度的指针(ctypes.c_void_p/int 指针)。
87
+ :param height_ptr: 用于接收高度的指针(ctypes.c_void_p/int 指针)。
88
+ :param buffer_ptr: 用于接收像素数据的指针(ctypes.c_void_p/unsigned char* 指针)。
89
+ :return: 0 表示成功,>0 表示失败。
90
+ """
91
+ return self.lib.nemu_capture_display(
92
+ connect_id,
93
+ display_id,
94
+ buf_len,
95
+ width_ptr,
96
+ height_ptr,
97
+ buffer_ptr,
98
+ )
99
+
100
+ def input_text(self, connect_id: int, text: str) -> int:
101
+ """
102
+ 输入文本。
103
+
104
+ API 原型:
105
+ `int nemu_input_text(int handle, int size, const char* buf)`
106
+
107
+ :param connect_id: 连接 ID。
108
+ :param text: 输入文本(utf-8)。
109
+ :return: 0 表示成功,>0 表示失败。
110
+ """
111
+ buf = text.encode('utf-8')
112
+ return self.lib.nemu_input_text(connect_id, len(buf), buf)
113
+
114
+ def input_touch_down(self, connect_id: int, display_id: int, x: int, y: int) -> int:
115
+ """
116
+ 发送触摸按下事件。
117
+
118
+ API 原型:
119
+ `int nemu_input_event_touch_down(int handle, int displayid, int x_point, int y_point)`
120
+
121
+ :param connect_id: 连接 ID。
122
+ :param display_id: 显示屏 ID。
123
+ :param x: 触摸点 X 坐标。
124
+ :param y: 触摸点 Y 坐标。
125
+ :return: 0 表示成功,>0 表示失败。
126
+ """
127
+ return self.lib.nemu_input_event_touch_down(connect_id, display_id, x, y)
128
+
129
+ def input_touch_up(self, connect_id: int, display_id: int) -> int:
130
+ """
131
+ 发送触摸抬起事件。
132
+
133
+ API 原型:
134
+ `int nemu_input_event_touch_up(int handle, int displayid)`
135
+
136
+ :param connect_id: 连接 ID。
137
+ :param display_id: 显示屏 ID。
138
+ :return: 0 表示成功,>0 表示失败。
139
+ """
140
+ return self.lib.nemu_input_event_touch_up(connect_id, display_id)
141
+
142
+ def input_key_down(self, connect_id: int, display_id: int, key_code: int) -> int:
143
+ """
144
+ 发送按键按下事件。
145
+
146
+ API 原型:
147
+ `int nemu_input_event_key_down(int handle, int displayid, int key_code)`
148
+
149
+ :param connect_id: 连接 ID。
150
+ :param display_id: 显示屏 ID。
151
+ :param key_code: 按键码。
152
+ :return: 0 表示成功,>0 表示失败。
153
+ """
154
+ return self.lib.nemu_input_event_key_down(connect_id, display_id, key_code)
155
+
156
+ def input_key_up(self, connect_id: int, display_id: int, key_code: int) -> int:
157
+ """
158
+ 发送按键抬起事件。
159
+
160
+ API 原型:
161
+ `int nemu_input_event_key_up(int handle, int displayid, int key_code)`
162
+
163
+ :param connect_id: 连接 ID。
164
+ :param display_id: 显示屏 ID。
165
+ :param key_code: 按键码。
166
+ :return: 0 表示成功,>0 表示失败。
167
+ """
168
+ return self.lib.nemu_input_event_key_up(connect_id, display_id, key_code)
169
+
170
+ def input_finger_touch_down(self, connect_id: int, display_id: int, finger_id: int, x: int, y: int) -> int:
171
+ """
172
+ 多指触摸按下。
173
+
174
+ API 原型:
175
+ `int nemu_input_event_finger_touch_down(int handle, int displayid, int finger_id, int x_point, int y_point)`
176
+
177
+ :param connect_id: 连接 ID。
178
+ :param display_id: 显示屏 ID。
179
+ :param finger_id: 手指编号(1-10)。
180
+ :param x: 触摸点 X 坐标。
181
+ :param y: 触摸点 Y 坐标。
182
+ :return: 0 表示成功,>0 表示失败。
183
+ """
184
+ return self.lib.nemu_input_event_finger_touch_down(connect_id, display_id, finger_id, x, y)
185
+
186
+ def input_finger_touch_up(self, connect_id: int, display_id: int, finger_id: int) -> int:
187
+ """
188
+ 多指触摸抬起。
189
+
190
+ API 原型:
191
+ `int nemu_input_event_finger_touch_up(int handle, int displayid, int slot_id)`
192
+
193
+ :param connect_id: 连接 ID。
194
+ :param display_id: 显示屏 ID。
195
+ :param finger_id: 手指编号(1-10)。
196
+ :return: 0 表示成功,>0 表示失败。
197
+ """
198
+ return self.lib.nemu_input_event_finger_touch_up(connect_id, display_id, finger_id)
199
+
200
+ # ------------------------------------------------------------------
201
+ # 内部工具
202
+ # ------------------------------------------------------------------
203
+
204
+ def __load_dll(self, mumu_root_folder: str) -> ctypes.CDLL:
205
+ """尝试多条路径加载 DLL。传入为 MuMu 根目录。"""
206
+ candidate_paths = [
207
+ # <= 4.x
208
+ os.path.join(mumu_root_folder, "shell", "sdk", "external_renderer_ipc.dll"),
209
+ os.path.join(
210
+ mumu_root_folder,
211
+ "shell",
212
+ "nx_device",
213
+ "12.0",
214
+ "sdk",
215
+ "external_renderer_ipc.dll",
216
+ ),
217
+ # >= 5.x
218
+ os.path.join(
219
+ mumu_root_folder, "nx_device", "12.0", "shell", "sdk", "external_renderer_ipc.dll"
220
+ ),
221
+ ]
222
+ for p in candidate_paths:
223
+ if not os.path.exists(p):
224
+ continue
225
+ try:
226
+ return ctypes.CDLL(p)
227
+ except OSError as e: # pragma: no cover
228
+ logger.warning("Failed to load DLL (%s): %s", p, e)
229
+ raise NemuIpcIncompatible("external_renderer_ipc.dll not found or failed to load.")
230
+
231
+ def __declare_prototypes(self) -> None:
232
+ """声明 DLL 函数原型,确保 ctypes 类型安全。"""
233
+ # 连接 / 断开
234
+ self.lib.nemu_connect.argtypes = [ctypes.c_wchar_p, ctypes.c_int]
235
+ self.lib.nemu_connect.restype = ctypes.c_int
236
+
237
+ self.lib.nemu_disconnect.argtypes = [ctypes.c_int]
238
+ self.lib.nemu_disconnect.restype = None
239
+
240
+ # 获取 display id
241
+ self.lib.nemu_get_display_id.argtypes = [ctypes.c_int, ctypes.c_char_p, ctypes.c_int]
242
+ self.lib.nemu_get_display_id.restype = ctypes.c_int
243
+
244
+ # 截图
245
+ self.lib.nemu_capture_display.argtypes = [
246
+ ctypes.c_int,
247
+ ctypes.c_uint,
248
+ ctypes.c_int,
249
+ ctypes.c_void_p,
250
+ ctypes.c_void_p,
251
+ ctypes.c_void_p,
252
+ ]
253
+ self.lib.nemu_capture_display.restype = ctypes.c_int
254
+
255
+ # 输入文本
256
+ self.lib.nemu_input_text.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_char_p]
257
+ self.lib.nemu_input_text.restype = ctypes.c_int
258
+
259
+ # 触摸
260
+ self.lib.nemu_input_event_touch_down.argtypes = [
261
+ ctypes.c_int,
262
+ ctypes.c_int,
263
+ ctypes.c_int,
264
+ ctypes.c_int,
265
+ ]
266
+ self.lib.nemu_input_event_touch_down.restype = ctypes.c_int
267
+
268
+ self.lib.nemu_input_event_touch_up.argtypes = [ctypes.c_int, ctypes.c_int]
269
+ self.lib.nemu_input_event_touch_up.restype = ctypes.c_int
270
+
271
+ # 按键
272
+ self.lib.nemu_input_event_key_down.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_int]
273
+ self.lib.nemu_input_event_key_down.restype = ctypes.c_int
274
+
275
+ self.lib.nemu_input_event_key_up.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_int]
276
+ self.lib.nemu_input_event_key_up.restype = ctypes.c_int
277
+
278
+ # 多指触摸
279
+ self.lib.nemu_input_event_finger_touch_down.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int]
280
+ self.lib.nemu_input_event_finger_touch_down.restype = ctypes.c_int
281
+
282
+ self.lib.nemu_input_event_finger_touch_up.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_int]
283
+ self.lib.nemu_input_event_finger_touch_up.restype = ctypes.c_int
284
+
285
285
  logger.debug("DLL function prototypes declared")