asweigart / pyautogui

A cross-platform GUI automation Python module for human beings. Used to programmatically control the mouse & keyboard.
BSD 3-Clause "New" or "Revised" License
10.22k stars 1.24k forks source link

pyautogui hotkey sometime unvalid #756

Open zero-fun opened 1 year ago

zero-fun commented 1 year ago

I paste content use (hotkey),but sometime unvalid. when i click the window,program run well.but if i open new window in program and copy、paste content,it dont work


win32api.ShellExecute(0, 'open', r'D:\Program Files\xx.exe', '', '', 1)
    hwnd = win32gui.FindWindow(None, 'xx')
    shell = win32com.client.Dispatch("WScript.Shell")
    shell.SendKeys('%')
    res = win32gui.SetForegroundWindow(hwnd)

    pyautogui.hotkey('ctrl','l')

    pyperclip.copy('hello')
    pyautogui.hotkey('Ctrl', 'v')
    pyautogui.hotkey('enter')