Python 模拟鼠标
原文:https://www.jianshu.com/p/c2e374ea63ec
# _*_ coding:UTF-8 _*_ import win32api import win32con import win32gui from ctypes import * import time # 原文:https://www.jianshu.com/p/9935bdf4df15 def mouse_absolute(x,y,x2,y2): SW = 1920 SH = 1080 windll.user32.SetCursorPos(x, y) #鼠标移动到 win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0) #左键按下 time.sleep(0.2) mw = int(x2 * 65535 / SW) mh = int(y2 * 65535 / SH) win32api.mouse_event(win32con.MOUSEEVENTF_ABSOLUTE + win32con.MOUSEEVENTF_MOVE, mw, mh, 0, 0) time.sleep(0.2) win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0) x=700 y=700 x2=700 y2=500 time.sleep(5) # 拖动 mouse_absolute(x,y,x2,y2) # 移动 #windll.user32.SetCursorPos(x, y)