def hold_and_drag(self,start,end,steps,button="left"):
hwnd = self.win_handler.get_hwnd()
if all(isinstance(elem, float) for elem in start):
start = self.to_pixel(start)
if all(isinstance(elem, float) for elem in end):
end = self.to_pixel(end)
step_x = (float(end[0] - start[0])) / steps
step_y = (float(end[1] - start[1])) / steps
if "right" in button.lower():
_button_state = win32con.MK_RBUTTON
_button_down = win32con.WM_RBUTTONDOWN
_button_up = win32con.WM_RBUTTONUP
elif "left" in button.lower():
_button_state = win32con.MK_LBUTTON
_button_down = win32con.WM_LBUTTONDOWN
_button_up = win32con.WM_LBUTTONUP
elif "middle" in button.lower():
_button_state = win32con.MK_MBUTTON
_button_down = win32con.WM_MBUTTONDOWN
_button_up = win32con.WM_MBUTTONUP
else:
raise SyntaxError('"Button" needs to contain "left", "right" or "middle"')
self.move(start)
l_param = win32api.MAKELONG(start[0], start[1])
time.sleep(0.1)
win32api.SendMessage(hwnd,_button_down,_button_state,l_param)
time.sleep(0.1)
x, y = start
for step in range(0,steps):
x += step_x
y += step_y
self.move((int(x),int(y)), button=button)
time.sleep(0.01)
l_param = win32api.MAKELONG(int(x), int(y))
win32api.SendMessage(hwnd,_button_up,0,l_param)
self._last_x = x
self._last_y = y
评论列表
文章目录