473,320 Members | 1,691 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to activate a new window in Python

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}")
Jul 18 '05 #1
4 3078
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" <mi******@yahoo.com> wrote in message
news:3c**************************@posting.google.c om...
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}")

Jul 18 '05 #2
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?


[... snip example code ...]

Have a look at:

http://www.brunningonline.net/simon/...es/000652.html

TJG
Jul 18 '05 #3
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 <mi*********@zoran.com>
http://tebeka.spymac.net
The only difference between children and adults is the price of the toys
Jul 18 '05 #4
What/where is SendKeys ?????????????????

mi******@yahoo.com (Milon) wrote in message >
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}")

Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Michael Wu | last post by:
I wonder if anyone know how to activate a window with a given window handler. I used to do this with the win32 API static native boolean SetForegroundWindow(int hwnd); I wonder if there is...
3
by: Michael Wu | last post by:
I wonder if anyone know how to activate a window with a given window handler. I used to do this with the win32 API static native boolean SetForegroundWindow(int hwnd); I wonder if there is...
2
by: Dave Booker | last post by:
I have a Windows form application that I generally run minimized. When a critical event occurs it instantiates another "Alert" form which I want to grab the user focus. In the Alert constructor...
1
by: pearturtle123 | last post by:
Hi, I am new to Python and I am using PAMIE to manipulate IE browser. Currently, I have IE window 1 launched, after I clicked on a link on window 1, a second IE window 2 isopened. Then, I want...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.