Search code examples
pythonkeyboardpyautogui

How to press pause key in python


I am creating a pyautogui automation that connect to a W3270 terminal (really old :)) this terminal is expecting pause key to be pressed, Apart pyautogui, I also tried Keyboard library, but i am unable to send pause

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')

Am I suppose to use keyboard to simulate 'pause' button? enter image description here


Solution

  • I found a solution using 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)