【问题标题】:How to press pause key in python如何在python中按下暂停键
【发布时间】:2021-11-27 23:26:14
【问题描述】:
我正在创建一个连接到 W3270 终端的 pyautogui 自动化(真的很旧 :))
该终端期望按下暂停键,
除了pyautogui,我也试过键盘库,但我无法发送暂停
import pyautogui
import keyboard
import constants as const
locateOnScreen(const.IPAIRE_TERMINAL_CONNECTED)
command = '/FOR SIGNON'
pause = '\u0019'
pyautogui.write(command)
time.sleep(1)
keyboard.send('pause')
我想用键盘来模拟“暂停”按钮吗?
【问题讨论】:
标签:
python
keyboard
pyautogui
【解决方案1】:
我找到了使用 pynput 的解决方案
import pyautogui
import constants as const
from pynput.keyboard import Key, Controller
locateOnScreen(const.IPAIRE_TERMINAL_CONNECTED)
command = '/FOR SIGNON'
pyautogui.write(command)
time.sleep(1)
keyboard = Controller()
keyboard.press(Key.pause)
keyboard.release(Key.pause)