The following code works with Python33 on Windows 7.
I used ctypes
.
The LPARAM
parameter for WM_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).
from ctypes import windll
WM_LBUTTONDBLCLK = 0x0203
MK_LBUTTON = 0x0001
if __name__=='__main__':
hProgman = windll.User32.FindWindowW( "Progman", 0 )
if hProgman != 0:
hFolder = windll.User32.FindWindowExW( hProgman, 0, "SHELLDLL_DefView", 0 )
if hFolder != 0:
hListView = windll.User32.FindWindowExW( hFolder, 0, "SysListView32", 0 )
if hListView != 0:
windll.User32.PostMessageW( hListView, WM_LBUTTONDBLCLK, MK_LBUTTON,
110 + (65536*32) )
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.