[python-win32] Fwd: Re: [Python-Help] Python script to clickOK

Misha Verplak mvmisha@yahoo.com
Sat, 14 Dec 2002 21:53:15 -0000


I have written functions for this and related actions as part of a
python-based windows automation & testing tool, coming soon to a sourceforge
near you :)

Anyway to do this try the following, after installing win32all:

#----------------------------------------------------------
# sample script to push the OK button on notepad's Font dialog box

import win32api, win32gui, win32con

# find the parent window (eg. dialog box),
# replace the last two parameters to match the appropriate window
hwnd = win32gui.FindWindowEx(0, 0, "#32770", "Font")

# find the OK button
hbutton = win32gui.FindWindowEx(hwnd, 0, "Button", "OK")

# mouse button click on the OK button, WM_COMMAND may work too
win32api.PostMessage(hbutton, win32con.WM_LBUTTONDOWN, 0, 0)
win32api.PostMessage(hbutton, win32con.WM_LBUTTONUP, 0, 0)
#----------------------------------------------------------

Kind regards,
Misha

----- Original Message -----
From: Jens B. Jorgensen <jens.jorgensen@tallan.com>
To: jtownsen <jtownsen@adobe.com>
Cc: <python-win32@python.org>
Sent: 14 December 2002 04:03
Subject: Re: [python-win32] Fwd: Re: [Python-Help] Python script to clickOK


This can certainly be done. You need to know the id of the button you
need to send the message to and then you can call the win32 SendMessage
call to deliver the click message or perhaps just ID_OK. At any rate the
tougher part is finding the right window on the screen to send the
message to. This isn't too hard to since you can probably figure out
which window is by its text property. You'll definitely want the
win32all extensions (or just install ActiveState's distribution which
includes this). You can start from the root window and enumerate all the
windows on the screen to find the right one. It helps to have an
understanding of how the win32 api calls work. I can help further, but I
don't have the code handy that enumerates through the windows but I have
done something just like this. Start looking at the win32 api calls.
Post back here and tell us how far you've gotten and we'll help you get
there.

jtownsen wrote:

> I'm hoping someone on the Win32 list can help me out. See below for
> details and an initial result.
>
>> From: Matthew Dixon Cowles <matt@mondoinfo.com>
>> To: jtownsen <jtownsen@adobe.com>
>> Cc: help@python.org
>> Reply-To: help@python.org
>> Subject: Re: [Python-Help] Python script to click OK
>> Date: Thu, 12 Dec 2002 19:54:01 -0600 (CST)
>>
>> > First off, I'm fairly new to Python but have been using Perl for
>> > some time.
>>
>> Welcome to Python!
>>
>> > I'd like to have a Python script click a Windows' OK button. I'd
>> > appreciate any suggestions.
>>
>> I'm sorry but I'm not much of a Windows guy and I don't know how to
>> do that. If someone else here knows better than I do, I'm sure that
>> they'll jump in and tell us both.
>>
>> There's probably something in Mark Hammond's win32all extensions that
>> will do it. They're at:
>>
>> http://starship.python.net/crew/mhammond/win32/Downloads.html
>>
>> but I don't know just what. The folks on the python-win32 list
>> probably know the details. There's more information about that list
>> at:
>>
>> http://mail.python.org/mailman/listinfo/python-win32
>>
>> I wish I had a better answer for you.
>>
>> Regards,
>> Matt
>
>
>
> _______________________________________________
> Python-win32 mailing list
> Python-win32@python.org
> http://mail.python.org/mailman/listinfo/python-win32


--
Jens B. Jorgensen
jens.jorgensen@tallan.com

"With a focused commitment to our clients and our people, we deliver value
through customized technology solutions"