键盘按键从 pyautogui 迁移到 pydirectinput
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import math
|
||||
import time
|
||||
import random
|
||||
import pyautogui
|
||||
import pydirectinput
|
||||
|
||||
class StuckHandler:
|
||||
# 针对 0.xxxx 坐标系优化
|
||||
@@ -61,27 +61,27 @@ class StuckHandler:
|
||||
|
||||
# 1. 全停
|
||||
for k in ("w", "a", "d", "s"):
|
||||
pyautogui.keyUp(k)
|
||||
pydirectinput.keyUp(k)
|
||||
|
||||
# 2. 倒车并转向(组合动作更有效)
|
||||
pyautogui.keyDown("s")
|
||||
pydirectinput.keyDown("s")
|
||||
turn_key = random.choice(["a", "d"])
|
||||
pyautogui.keyDown(turn_key)
|
||||
pydirectinput.keyDown(turn_key)
|
||||
|
||||
# 倒车时间稍长一点,离开障碍物
|
||||
time.sleep(0.5)
|
||||
|
||||
# 3. 尝试跳跃脱离地形卡位
|
||||
pyautogui.press("space")
|
||||
pydirectinput.press("space")
|
||||
time.sleep(0.5)
|
||||
|
||||
pyautogui.keyUp(turn_key)
|
||||
pyautogui.keyUp("s")
|
||||
pydirectinput.keyUp(turn_key)
|
||||
pydirectinput.keyUp("s")
|
||||
|
||||
# 4. 往前稍微走一步,重新锁定坐标
|
||||
pyautogui.keyDown("w")
|
||||
pydirectinput.keyDown("w")
|
||||
time.sleep(0.5)
|
||||
pyautogui.keyUp("w")
|
||||
pydirectinput.keyUp("w")
|
||||
|
||||
self.reset()
|
||||
print(">>> 脱困尝试结束")
|
||||
|
||||
Reference in New Issue
Block a user