Mouseclick

garyr at fidalgo.net garyr at fidalgo.net
Mon May 2 22:22:34 EDT 2005


Terje Johan Abrahamsen wrote:
> Hello.
>
> I have been trying desperately for a while to make Python push the
> left mousebutton. I have been able to let Python push a button in a
> box:
>
> def click(hwnd):
>     win32gui.SendMessage(hwnd, win32con.WM_LBUTTONDOWN, 0, 0)
>     win32gui.SendMessage(hwnd, win32con.WM_LBUTTONUP, 0, 0)
>
> optDialog = findTopWindow(wantedText="Options")
>
> def findAButtonCalledOK(hwnd, windowText, windowClass):
>     return windowClass == "Button" and windowText == "OK"
> okButton = findControl(optDialog, findAButtonCalledOK)
>
> click(okButton)
>
> As described here, http://tinyurl.com/cwjls. But, that is not what I
> am looking for. I would like to specify some coordinates such as
> windll.user32.SetCursorPos(450, 370) and thereafter click the left
> mousebutton at that place.
>
> I know that the sollution lies somewhere with Microsoft
> (http://www.6URL.com/FED), but cannot understand how to make Python
> click the button regardless of how much I try.
>
> Thanks in advance.


Another, perhaps not so cool, way of doing this is to just invoke the
mouse handler functions directly. e.g.:

class Event:
    def __init__(self, x, y):
        self.x = x
        self.y = y

class Whatever:
   .
   .
    def mouseClick(self, event):
        self.mouseDown(event)    # link to ButtonPress handler
        self.mouseUp(event)      # link to ButtonRelease handler

   ...
   event.x, event.y = 123, 456
   self.mouseClick(event)




More information about the Python-list mailing list