[python-win32] Simulating a mouse click - lParam

Rickey, Kyle W Kyle.Rickey at bakerhughes.com
Fri Dec 5 23:56:09 CET 2008


Apparently I jumped the gun.

I tried:

lParam = (y << 16) | x
win32gui.SendMessage(top_hwnd, win32con.WM_LBUTTONDOWN, 0, lParam)
win32gui.SendMessage(top_hwnd, win32con.WM_LBUTTONUP, 0, lParam)

with x and y 1st being on-screen coordinates, and 2nd with x and y being
referenced from the corner of my window. I left the TCM_SETCURSEL code
un-commented when I ran it the first time.

-Kyle Rickey

-----Original Message-----
From: python-win32-bounces+kyle.rickey=bakerhughes.com at python.org
[mailto:python-win32-bounces+kyle.rickey=bakerhughes.com at python.org] On
Behalf Of Rickey, Kyle W
Sent: Friday, December 05, 2008 4:52 PM
To: python-win32 at python.org
Subject: Re: [python-win32] Simulating a mouse click - lParam

Thanks Tim. I used the following to select my tab of interest:

TCM_SETCURSEL = 0x130C
win32gui.SendMessage(hwnd, TCM_SETCURSEL, 3, 0)

However, according to MSDN:
http://msdn.microsoft.com/en-us/library/bb760612(VS.85).aspx
"Remarks

    A tab control does not send a TCN_SELCHANGING or TCN_SELCHANGE
notification message when a tab is selected using this message."

So of course nothing happens after the tab is selected. Ie, the window
is not updated to show the different controls etc. And unfortunately,
the window of interest is a 3rd party app, so I don't have direct access
to the controls and their methods :(

Also using:

x = 212
y = 66
lParam = (y << 16) | x
win32gui.SendMessage(top_hwnd, win32con.WM_LBUTTONDOWN, 0, lParam)
win32gui.SendMessage(top_hwnd, win32con.WM_LBUTTONUP, 0, lParam)

Selects the tab (albeit not as "elegantly"), but again, the window does
not update. Any ideas?

-Kyle Rickey

-----Original Message-----
From: python-win32-bounces+kyle.rickey=bakerhughes.com at python.org
[mailto:python-win32-bounces+kyle.rickey=bakerhughes.com at python.org] On
Behalf Of Tim Roberts
Sent: Friday, December 05, 2008 4:25 PM
To: Python-Win32 List
Subject: Re: [python-win32] Simulating a mouse click - lParam

Rickey, Kyle W wrote:
>
> Let's say I've got a window for which I want to simulate a mouse click
> at a specific x, y coordinate. I already have the hwnd but I'm not
> sure how to construct the lParam. I've used SendMessage in the past to
> click on buttons, etc., but I knew their hwnds. How do I construct the
> lParam. Per the MSDN docs:
>
>  
>
> http://msdn.microsoft.com/en-us/library/ms645607(VS.85).aspx
> <http://msdn.microsoft.com/en-us/library/ms645607%28VS.85%29.aspx>
>
> /lParam/
>
> The low-order word specifies the x-coordinate of the cursor. The
> coordinate is relative to the upper-left corner of the client area.
>
> The high-order word specifies the y-coordinate of the cursor. The
> coordinate is relative to the upper-left corner of the client area.
>
> lParam = ???
>
> win32gui.SendMessage(hwnd, win32con.WM_LBUTTONDOWN, 0, lParam)
>
> win32gui.SendMessage(hwnd, win32con.WM_LBUTTONUP, 0, lParam)
>
>  
>
> Any help would be greatly appreciated. I also can't help but wonder if
> I'm going about this the wrong way. My end goal is clicking on a
> certain Tab in a TabCtrl (in this case _/wx/_SysTabCtl32). I used
> EnumChildWindows to find all the main window's children, but couldn't
> find the tabs. So figured I would try to 'click' on the tab.
>

Two ways.  This works as long as both coordinates are positive:
    lParam = (y << 16) | x

The more robust way is like this:
    lParam = struct.unpack( 'L', struct.unpack( 'hh', x, y ) )[0]

However, it would be much better to talk to the tab control directly. 
Are you doing this from inside the owning wx application?  If so, you
should be able to get the tab control object and call the methods
directly.  Even if you can only get the handle, you can use
TCM_SETCURSEL.

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.

_______________________________________________
python-win32 mailing list
python-win32 at python.org
http://mail.python.org/mailman/listinfo/python-win32
_______________________________________________
python-win32 mailing list
python-win32 at python.org
http://mail.python.org/mailman/listinfo/python-win32


More information about the python-win32 mailing list