如何在 python 中按下暂停键

How to press pause key in python

我正在创建一个连接到 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')

我应该使用键盘来模拟 'pause' 按钮吗?

我找到了使用 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)