How to activate a new window in Python

Discussion in 'Python' started by Milon, Jul 19, 2004.

  1. Milon

    Milon Guest

    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}")
     
    Milon, Jul 19, 2004
    #1
    1. Advertising

  2. Milon

    Larry Bates Guest

    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}")
     
    Larry Bates, Jul 19, 2004
    #2
    1. Advertising

  3. Milon

    Tim Golden Guest

    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/blog/archives/000652.html

    TJG
     
    Tim Golden, Jul 19, 2004
    #3
  4. Milon

    Miki Tebeka Guest

    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
     
    Miki Tebeka, Jul 19, 2004
    #4
  5. Milon

    Tony C Guest

    What/where is SendKeys ?????????????????

    (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}")
     
    Tony C, Jul 20, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hrvoje Vrbanc
    Replies:
    1
    Views:
    1,101
    Hrvoje Vrbanc
    Aug 27, 2003
  2. =?Utf-8?B?Tm92aWNl?=
    Replies:
    2
    Views:
    6,718
    Alan Ferrandiz Langley
    Jun 9, 2004
  3. Mark Harris

    activate a browser window in Perl

    Mark Harris, Jan 31, 2007, in forum: Perl
    Replies:
    0
    Views:
    2,037
    Mark Harris
    Jan 31, 2007
  4. Junkone
    Replies:
    2
    Views:
    226
    Jarmo Pertman
    Oct 27, 2010
  5. Gelonida N
    Replies:
    2
    Views:
    335
    Gelonida N
    Aug 13, 2012
Loading...

Share This Page