我正在尝试用 Python 编写一个使用 pynput 打开 Windows PowerShell 的脚本。我的程序将打开 PowerShell 并在 PowerShell 中写入。
这是我到目前为止得到的:
from pynput.keyboard import Key, Controller
import time
keyboard = Controller()
keyboard.press(Key.cmd)
keyboard.release(Key.cmd)
time.sleep(0.3)
keyboard.type("powershell")
keyboard.press(Key.ctrl) # This opens the script with a UAC request.
keyboard.press(Key.shift) #
keyboard.press(Key.enter) #
keyboard.release(Key.ctrl) #
keyboard.release(Key.shift) #
keyboard.release(Key.enter) #
time.sleep(0.5)
keyboard.press(Key.left)
time.sleep(0.3)
keyboard.release(Key.left)
time.sleep(0.3)
keyboard.press(Key.enter)
keyboard.release(Key.enter)
我尽量保持井井有条。
我不明白为什么,但我的程序在第 18 行的“time.sleep(0.5)”之后停止。
感谢您花时间回复,问候,塞缪尔