feat: 添加确保输入框获得焦点的选项,优化文本粘贴功能
This commit is contained in:
1 parent
a3b15e3965
commit
df96e5fc83
4 files changed
+172
-21
No files matched your search
+19
-18
@@ -3087,7 +3087,7 @@ class underlying_operations:
|
||||
time_module.sleep(0.25)
|
||||
self.restore_ime(device_id, prev)
|
||||
|
||||
def paste_text_at(self, device_id: str, x: int, y: int, text: str) -> bool:
|
||||
def paste_text_at(self, device_id: str, x: int, y: int, text: str, ensure_focus: bool = True) -> bool:
|
||||
"""最简单的“粘贴到输入框”方法。
|
||||
|
||||
流程:点击输入框获取焦点 -> 设置剪贴板 -> 发送 KEYCODE_PASTE(279)。
|
||||
@@ -3099,23 +3099,24 @@ class underlying_operations:
|
||||
|
||||
# 先确保输入框获得焦点
|
||||
try:
|
||||
try:
|
||||
print(
|
||||
f"[Underlying] paste_text_at: clicking to focus device_id={device_id} coord=({x},{y})"
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
self.click(device_id, int(x), int(y))
|
||||
time_module.sleep(0.2)
|
||||
# 有些输入框第一次点不进,补一次轻点
|
||||
try:
|
||||
print(
|
||||
f"[Underlying] paste_text_at: clicking again to ensure focus device_id={device_id} coord=({x},{y})"
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
self.click(device_id, int(x), int(y))
|
||||
time_module.sleep(0.15)
|
||||
if ensure_focus:
|
||||
try:
|
||||
print(
|
||||
f"[Underlying] paste_text_at: clicking to focus device_id={device_id} coord=({x},{y})"
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
self.click(device_id, int(x), int(y))
|
||||
time_module.sleep(0.2)
|
||||
# 有些输入框第一次点不进,补一次轻点
|
||||
try:
|
||||
print(
|
||||
f"[Underlying] paste_text_at: clicking again to ensure focus device_id={device_id} coord=({x},{y})"
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
self.click(device_id, int(x), int(y))
|
||||
time_module.sleep(0.15)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
Reference in new issue
Block a user