How to activate a new window in Python

I am new to Python, and I just wrote a simple script to launch an
application from the windows's start menu's run command. (see code as
follow) There is an "OK" button on the new application I launched,
but I can't get Python to click on it because the new window is not in
focus and I read somewhere off the web that I need to activate the new
window first before I can do anything on the new window. I couldn't
find any useful information off the web, so, can someone please show
me how to do it?

Advertisements

Just run the application with os.system or use
win32process.CreateProcess to execute the
application (which gives you more control
over the window size, environment, etc.).
win32process is part of win32all extensions.

HTH,
Larry Bates
Syscon, Inc.

"Milon" <> wrote in message
news:...
> Hi all,
>
> I am new to Python, and I just wrote a simple script to launch an
> application from the windows's start menu's run command. (see code as
> follow) There is an "OK" button on the new application I launched,
> but I can't get Python to click on it because the new window is not in
> focus and I read somewhere off the web that I need to activate the new
> window first before I can do anything on the new window. I couldn't
> find any useful information off the web, so, can someone please show
> me how to do it?
>
> Really appreciate it,
> Milon
>
> __________________________________________________________________
>
> import SendKeys
>
> # starts the TempApp using the windows start menu
> # run option
> def StartTempApp():
> SendKeys.SendKeys( "{LWIN}{SLEEP .25}r")
> SendKeys.SendKeys( "C:\\TempApp\\bin\\main")
> SendKeys.SendKeys( "{ENTER}")
>
> # tab to OK button on the application and hit enter
> def StartTempApp():
> SendKeys.SendKeys( "{TAB}{TAB}{ENTER}")

Advertisements

Milon wrote:
> Hi all,
>
> I am new to Python, and I just wrote a simple script to launch an
> application from the windows's start menu's run command. (see code as
> follow) There is an "OK" button on the new application I launched,
> but I can't get Python to click on it because the new window is not in
> focus and I read somewhere off the web that I need to activate the new
> window first before I can do anything on the new window. I couldn't
> find any useful information off the web, so, can someone please show
> me how to do it?

Hello Milon,
> I am new to Python, and I just wrote a simple script to launch an
> application from the windows's start menu's run command. (see code as
> follow) There is an "OK" button on the new application I launched,
> but I can't get Python to click on it because the new window is not in
> focus and I read somewhere off the web that I need to activate the new
> window first before I can do anything on the new window. I couldn't
> find any useful information off the web, so, can someone please show
> me how to do it?
I don't know where "SendKeys" is coming from but you can use AutoIt through
the COM interface or using ctypes.

Bye.
--
------------------------------------------------------------------------
Miki Tebeka <>http://tebeka.spymac.net
The only difference between children and adults is the price of the toys

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!