开发者

Problem with dragging mouse cursor with Python

开发者 https://www.devze.com 2023-01-12 18:42 出处:网络
Could someone tell me why this doesn\'t work? def selectAndCopy(x,y,z,w): ctypes.windll.user32.SetCursorPos(x,y)

Could someone tell me why this doesn't work?

def selectAndCopy(x,y,z,w):
    ctypes.windll.user32.SetCursorPos(x,y)
    time.sleep(1)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0)
    time.sleep(1)
    ctypes.windll.user32.SetCursorPos(z,w)
    time.sleep(1)
    win32api.mouse_event(win32co开发者_JAVA技巧n.MOUSEEVENTF_LEFTUP, 0, 0, 0)
    time.sleep(1)
    shell.SendKeys('^c')

the code isn't dragging to the first location to the second, it's only moving it.


Don't reinvent the wheel! There's the package pywinauto that has a ready-to-use function for this:

pywinauto.controls.HwndWrapper.DragMouse(button='left', pressed='', 
                                         press_coords=(0, 0), 
                                         release_coords=(0, 0))
0

精彩评论

暂无评论...
验证码 换一张
取 消