Kimmo Kekkonen wrote: > > I were wondering if it is possible to use Python to select a window > (by title or somehow) and then input text into it? I'd need the trick > to input text to program I am running from cmd. When program opens it > also opens one "GUI" window and focus to the cmd will lost. Now I'd > like to get focus back to cmd and then input text into it. I tried > PIPEs with Popen but after 6 hours of work it still did not work. I > think it is because of this my program.
Windows GUI apps do not communicate using stdin and stdout. Instead, everything is done via window messages. You need to use the Win32 API for this. You can use win32gui.FindWindow to locate your window by title. If you're trying to send to a particular control inside that window, you'll probably have to enumerate the children of that window, which can be a bit tedious. Once you have your target, you might be able to use win32gui.SetWindowText to send a string to it (depending on the control type). You can use other messages to click buttons in the window. > Also I am trying to close active window. Is there a solution to send > "alt+f4" to currently active window? You can use win32api.SendMessage to send a WM_CLOSE message to the window. That's usually enough. > I managed to do these tricks using WSH but I would like to use Python > so I would not have to do these "window activations and closing" by > WSH. Then I will have 100% Python script without any others. If you post your WSH script, perhaps we can translate it for you. -- Tim Roberts, t...@probo.com Providenza & Boekelheide, Inc. _______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32