george
george

Reputation: 705

How can I send text when the window is minimized?

I have tried using python libraries: pyautogui + pwinauto. But to no avail. Once the window is minimized the text is no longer send.

code snippet:

import pyautogui
import time
pyautogui.hotkey('win')
time.sleep(1)
pyautogui.typewrite('notepad')
pyautogui.hotkey('enter')
time.sleep(2)
pyautogui.typewrite('test aaaaaaaaaaaaaa bbbbbbbbbbbb cccccccccc ')

Upvotes: 6

Views: 5997

Answers (1)

Vasily Ryabov
Vasily Ryabov

Reputation: 9991

pywinauto can send text to a minimized window.

from pywinauto import Application
app = Application(backend="win32").start('notepad.exe')
app.UntitledNotepad.minimize()
app.UntitledNotepad.Edit.set_text('some text\nsecond line')

type_keys() method requires a control to be in focus. But set_text sends WM_SETTEXT message by window handle, so focus is not required.

Another example of script dealing with minimized window: Python - Control window with pywinauto while the window is minimized or hidden

Upvotes: 7

Related Questions