I'm trying to click somewhere on the desktop, I'm using python with win32 api, I'm using python 32 bit but my computer is a 64 bit computer. I believe the lParam variable isn't holding the value I'm expecting, and I'm still a bit confused about this variable itself, lets say I import it from wintypes can anyone tell me how to use it? Why does my function below not work?
I have a function as following, this doesn't seem to work:
def clickDesktop(x=0, y=0):
# Get handle to desktop window
desktop = win32gui.GetDesktopWindow()
# Create variable lParam that contains the x-coordinate in the low-order word while
# the high-order word contains the y coordinate.
lParam = y << 16 | x
# Click at x, y in the desktop window
win32gui.PostMessage(desktop, win32con.WM_LBUTTONDOWN, MK_LBUTTON, lParam)
win32gui.PostMessage(desktop, win32con.WM_LBUTTONUP, 0, lParam)
The following code works with Python33 on Windows 7.
I used
ctypes
.The
LPARAM
parameter forWM_LBUTTONDBLCLK
combines x and y in a single 32 bits value.When I run that code, it opens the "My Computer" Icon, located at the upper left corner of my Desktop (my TaskBar is also on the left, hence the high value of 110 for x).
EDIT the
WM_LBUTTON*
messages are normally posted by Windows to the window under the pointer. The desktop window has child windows, and that's those child windows which are "under the pointer". If you want to use the PostMessage API, you need to know to what window you will post the message.If you don't want to bother with windows hierarchy, the just use
SendInput
. Window will then do the work for you and finally post the mouse message to the correct handle.