Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ')
like image 326
george Avatar asked Oct 08 '15 15:10

george


1 Answers

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

like image 161
Vasily Ryabov Avatar answered Sep 21 '22 23:09

Vasily Ryabov