def arrasta_Rigth(x1, y1, x2, y2): x1, y1 = int(x1), int(y1) sleep(0.5) SetCursorPos((x1, y1)) mouse_event(MOUSEEVENTF_RIGHTDOWN, x1, y1, 0, 0) sleep(0.5) SetCursorPos((x2, y2)) sleep(0.5) mouse_event(MOUSEEVENTF_RIGHTUP, x2, y2, 0, 0) sleep(0.5)
def clickMouse( x, y, timeDown=.1 ): #FIXME need a way to change focus back to the original window! """click ye mouse""" mX, mY = wig.GetCursorPos() #save the position so we can return to it SetCursorPos((x, y)) mouse_event(wic.MOUSEEVENTF_LEFTDOWN, x, y, 0, 0) sleep(timeDown) mouse_event(wic.MOUSEEVENTF_LEFTUP, x, y, 0, 0) SetCursorPos((mX, mY))
def _sendRclick(self, hwnd, msg): # IPython magic %paste does not work for remote ssh python # or Windows Subsystem for Linux, so let's send right click using win32 def _pasting(hwnd, msg): sublime.set_clipboard(msg) sleep(0.1) # important! # sending right-click to paste over mouse_event(MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_ABSOLUTE, 0, 0) sleep(0.1) # important! mouse_event(MOUSEEVENTF_RIGHTUP | MOUSEEVENTF_ABSOLUTE, 0, 0) # send enter; int('0x1C0001', 0) works both on WSL and cmd PostMessage(hwnd, WM_KEYDOWN, VK_RETURN, int('0x1C0001', 0)) PostMessage(hwnd, WM_KEYUP, VK_RETURN, int('0xC0000001', 0)) try: # https://stackoverflow.com/a/15503675/566035 shell = Dispatch("WScript.Shell") shell.SendKeys( '%' ) # Sending Alt key goes around windows security policy change SetForegroundWindow(hwnd) except: self.view.show_popup('Invalid handle ({})'.format(hwnd)) return # move mouse to the center of that window oldx, oldy = GetCursorPos() x1, y1, x2, y2 = GetWindowRect(hwnd) x = int((x1 + x2) / 2) y = int((y1 + y2) / 2) SetCursorPos((x, y)) lineN = len(self.view.lines(self.view.sel()[0])) # we need to use %cpaste magic to avoid indentation error # in case more than 2 lines have indentation. if lineN > 2: _pasting(hwnd, r"%cpaste") _pasting(hwnd, msg) _pasting(hwnd, "--") else: _pasting(hwnd, msg) # bring back the mouse cursor SetCursorPos((oldx, oldy)) # bring back the focus to sublime, if subl_handle is known to the plugin if subl_handle: SetForegroundWindow(subl_handle) shell.SendKeys('%') # cancel the Alt key evoked menu
def Click(cords, times=1): for click in range(times): x = cords[0] y = cords[1] SetCursorPos((x, y)) mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0) mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0)
def left_and_right_click(self, left_offset, top_offset): pos = self.window.get_box(left_offset, top_offset) SetCursorPos(pos) mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0) mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0) mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0) mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
def track_input_initialize(self): """ this function tracks the received information from the server and analyzes it. If it is an io input it sends it to the correct input processor. On the other hand, if this input is an input that declares a change in pc control oto this client it analyzes the information and changes the mouse position accordingly :return: None """ while 1: data, adrr = self._get_data_handle.recv() input_type = data.split("|")[0] data = data[data.index('|') + 1:] if input_type == "1": io_device_processor_index = self.identify_io_device(data) processor = \ self._io_devices_processors[io_device_processor_index] processor.process_input(data[data.index('|') + 1:]) elif input_type == "2": args = data.split('|') direction_change, position, resolution = \ args[0], eval(args[1]), eval(args[2]) new_position = self.get_new_position(direction_change, position, resolution) print("setting mouse to", new_position) SetCursorPos(new_position)
def track_changes(self): """ this function checks if the mouse collides with one the screen's borders and according to so sends msg to the server about the change :return: None """ # build the resolution to check for changes resolution_x, resolution_y = InputProcessor.get_screen_resolution() check_resolution_x, check_resolution_y = \ resolution_x - 1, resolution_y - 1 while 1: pos_x, pos_y = InputProcessor.get_mouse__position() # building the return msg according to the side of the screen's # border that the mouse collides (if there is one) return_message = "" if pos_x <= 1: return_message = "l" elif pos_x >= check_resolution_x: return_message = "r" if pos_y <= 1: return_message = "u" elif pos_y >= check_resolution_y: return_message = "d" if return_message: # return the side of collision, current position and resolution # for ratio checking in the other client's pc SetCursorPos((int(resolution_x / 2), int(resolution_y / 2))) self._send_data_handle.send( str(return_message) + "|" + str((pos_x, pos_y)) + "|" + str((resolution_x, resolution_y)))
def setCursorPos(self, pos): """ 设置鼠标位置 :param pos: :param self: """ SetCursorPos(pos)
def Click(cords,times): for click in range(times): info("Click() clicking") x=cords[0] y=cords[1] SetCursorPos((x,y)) mouse_event(MOUSEEVENTF_LEFTDOWN,x,y,0,0) mouse_event(MOUSEEVENTF_LEFTUP,x,y,0,0) sleep(5)
def mmove(fin_pos): init_pos = GetCursorPos() bez1 = mouse_bez(init_pos, fin_pos, 30, 1000) # bez1 = [[round(v) for v in x] if type(x) is not str else x for x in bez1] for point in bez1: # SetCursorPos((point[0], point[1])) SetCursorPos((int(point[0]), int(point[1])))
def moveMouseTo(mouse, Newpos): x, y = mouse.position dx = Newpos[0] - x dy = Newpos[1] - y if (platform.system() == "Windows"): from win32api import SetCursorPos SetCursorPos((int(Newpos[0]), int(Newpos[1]))) else: mouse.move(dx, dy) return
def move(toPoint, duration=2, humanCurve=None): # moving your mouse in the bezier curve path fromPoint = GetCursorPos() if not humanCurve: humanCurve = HumanCurve(fromPoint, toPoint) for point in humanCurve.points: sleep(duration / len(humanCurve.points)) SetCursorPos((int(point[0]), int(point[1])))
def set_mouse_visible(self, _visible): """ Toggle visibility of mouse cursor """ if self.isReady: self.switch_to() super().set_mouse_visible(_visible) if not (sys.platform == 'win32'): self.set_exclusive_mouse(not _visible) else: if not (_visible): SetCursorPos((0, 0))
def fazerCompra(lote, coordenadasLotes, coordenadaBotaoComprar): xBotao = coordenadaBotaoComprar[0] yBotao = coordenadaBotaoComprar[1] #Click no lote if lote == 1: x = int(coordenadasLotes[0][1][0]) y = int(coordenadasLotes[0][1][1]) elif lote == 10: x = int(coordenadasLotes[1][1][0]) y = int(coordenadasLotes[1][1][1]) elif lote == 100: x = int(coordenadasLotes[2][1][0]) y = int(coordenadasLotes[2][1][1]) #Click no lote SetCursorPos((x, y)) mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, x, y, 0, 0) sleep(0.05) mouse_event(win32con.MOUSEEVENTF_LEFTUP, x, y, 0, 0) sleep(0.05) #Click no Comprar SetCursorPos((xBotao, yBotao)) mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, xBotao, yBotao, 0, 0) sleep(0.05) mouse_event(win32con.MOUSEEVENTF_LEFTUP, xBotao, yBotao, 0, 0) sleep(0.05) sleep(0.05) #Enter para realizar compra keybd_event(0x0D, 0, 0, 0) sleep(0.05) keybd_event(0x0D, 0, win32con.KEYEVENTF_KEYUP, 0) sleep(0.2)
def vaiEntradaSiena(semaforo): from time import sleep LAG = semaforo.getLAG() sleep(1) arrasta_Rigth(840, 300, 1050, 170) x, y = 640, 100 sleep(0.5) SetCursorPos((x, y)) sleep(1) mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0) sleep(0.02) arrasta_Rigth(800, 200, 30, 400) sleep(1) mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0) sleep(3 + LAG)
def andaGluto(semaforo): from time import sleep LAG = semaforo.getLAG() x, y = 837, 115 sleep(0.5) SetCursorPos((x, y)) sleep(0.5) mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0) sleep(2) press(KEY_D, 0.2) sleep(2) press(KEY_D, 0.2) sleep(2) mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0) press(KEY_W, 1)
def main(argv=None): pargs = parse_args(argv) anchor = prev = GetCursorPos() delay = pargs.delay counter = count(pargs.iterations, -1) while next(counter) > 0: sleep(delay) if GetCursorPos() == prev: # No user action detected - make a move base = anchor if pargs.anchor else prev SetCursorPos([i + randint(-5, 5) for i in base]) if pargs.click: mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0) sleep(0.2) mouse_event(MOUSEEVENTF_LEFTUP, 0, 0) else: # Moved since last check - reset the anchor delay = 10 anchor = GetCursorPos() delay = pargs.delay prev = GetCursorPos()
def reset_mouse(): SetCursorPos((int(GetSystemMetrics(0) / 2), int(GetSystemMetrics(1) / 2)))
def set_middle_mouse(): SetCursorPos(get_middle_position())
def click(tup): x = tup[0] y = tup[1] SetCursorPos((x, y)) mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0) mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0)
def mouseClick(x, y): SetCursorPos((x, y)) mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0) mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0)
def click_right(x, y): x, y = int(x), int(y) SetCursorPos((x, y)) mouse_event(MOUSEEVENTF_RIGHTDOWN, x, y, 0, 0) # sleep(0.1) mouse_event(MOUSEEVENTF_RIGHTUP, x, y, 0, 0)
def leftClick(x, y): SetCursorPos([x, y]) time.sleep(0.1) mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0) time.sleep(0.1) mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0)
def set_cursor_pos(x: int, y: int): try: SetCursorPos([x, y]) except: log_record('не удалось установить курсор в позицию: ' + str(x) + '/' + str(y))
def click_left(x, y): x, y = int(x), int(y) SetCursorPos((x, y)) mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0) # sleep(0.1) mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0)
def _move(self,x,y): """ Executes mouse move """ SetCursorPos((x,y))
def resetMousePosition(self): screen_x, screen_y = int(self.canvas.winfo_rootx()), int(self.canvas.winfo_rooty()) SetCursorPos( (int(screen_x + self.width / 2), int(screen_y + self.height / 2))) # set cursor at center of canvas
def move_to(self, x: int, y: int): pt = (x, y) self.logger.debug(f'moving to {x}, {y}') SetCursorPos(pt)
def send_mouse_event(x, y): SetCursorPos((x, y)) mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, x, y, 0, 0) mouse_event(win32con.MOUSEEVENTF_LEFTUP, x, y, 0, 0)
def _move_mouse_cursor_to_origin(self): if is_windows(): from win32api import SetCursorPos SetCursorPos((0, 0))