simulate mouse click across application (win32)

Alex Martelli alex at magenta.com
Sat Aug 26 07:01:37 EDT 2000


"Sugree Phatanapherom" <b40sup at ku.ac.th> wrote in message
news:39A79054.9648A6FC at ku.ac.th...
> I try to sendmessage across process to simulate mouse click but didn't
> work.
>
> wnd = win32ui.FindWindow(None,"PythonWin")
> wnd.SetForegroundWindow()
> win32api.SetCursorPos(100,100) # somewhere in windows
> wnd.SendMessage(win32con.WM_LBUTTONDOWN,0,0)
> wnd.SendMessage(win32con.WM_LBUTTONUP,0,0)
>
> Any ideas?

When you actually clic a mouse, there's a flurry of lower level
messages, (WM_NC... and friends), which you're not fully
reproducing here (and are pretty hard to reproduce!).  That's
why Win32, to allow simulating mouse-clics, provides the
SendInput API (in NT4 SP4, and Win98, and later; there was
a mouse_event API in older versions, but I'm not sue if it
works well with modern platforms).  Not sure if win32api
covers it, though.


Alex






More information about the Python-list mailing list