def process_chunk(chunk, out_chunk, time_info, status): left_signal = chunk[:, 0] left_signal[left_signal == 0] = 0.00000001 max_db = np.max(np.abs(left_signal)) max_db = DB_MUL * np.log10(max_db) if max_db > 5: mouse.click() x_pct = np.interp(max_db, [SCREEN_LEFT_DB, SCREEN_RIGHT_DB], [0, 0.999999]) hz = determine_pitch(left_signal) y_pct = np.interp(hz, [SCREEN_TOP_HZ, SCREEN_BOT_HZ], [0, 0.999999]) MOUSE_TARGET[0] = int(screen_size[0] * x_pct) MOUSE_TARGET[1] = int(screen_size[1] * y_pct) c_x, c_y = mouse.get_pos() t_x, t_y = MOUSE_TARGET new_pos = np.array([ new_mouse_position(c_x, t_x, MOUSE_SPEED), new_mouse_position(c_y, t_y, MOUSE_SPEED) ]) mouse.move( max(0, min(new_pos[0], screen_size[0] - 1)), max(0, min(new_pos[1], screen_size[1] - 1)) ) out_chunk[:] = np.zeros_like(chunk) return continue_flag
def get_location(): global cx, cy while True: if stop == 'y': break cx, cy = mouse.get_pos() sleep(1)
def move(self, x, y): """Human mouse movement """ startCoords = get_pos() coordsAndDelay = self._calcCoordsAndDelay(startCoords, (x, y)) print coordsAndDelay print x, y for x, y, delay in coordsAndDelay: move(int(x), int(y)) sleep(delay / 1000) move_mouse_to(x, y)
def move_radius(self, coord): """Human mouse movement """ x = random.randint(coord[0] + 6, coord[2] + coord[0] - 6) y = random.randint(coord[1] + 6, coord[3] + coord[1] - 6) print x, y startCoords = get_pos() coordsAndDelay = self._calcCoordsAndDelay(startCoords, (x, y)) for x, y, delay in coordsAndDelay: move(int(x), int(y)) sleep(delay / 1000) move_mouse_to(x, y)
def singlemove(queryParams,content_type): content = "OK" if queryParams.has_key('disx') and queryParams.has_key('disy'): disx = int(queryParams['disx']) disy = int(queryParams['disy']) x,y = mouse.get_pos() xx,yy = disx+x,disy+y print(disx,disy,x,y,xx,yy) try: mouse.move(xx,yy) except ValueError: print("out of side") return content_type,content
def singlemove(queryParams, content_type): content = "OK" if queryParams.has_key('disx') and queryParams.has_key('disy'): disx = int(queryParams['disx']) disy = int(queryParams['disy']) x, y = mouse.get_pos() xx, yy = disx + x, disy + y print(disx, disy, x, y, xx, yy) try: mouse.move(xx, yy) except ValueError: print("out of side") return content_type, content
def makeMove(self, move): self.gameState.makeMove(move) firstPt, secondPt = move.pointTuple() absFirst = self.boardToAbsPt(firstPt) absSecond = self.boardToAbsPt(secondPt) lastX, lastY = mouse.get_pos() mouse.move(absFirst.x, absFirst.y) mouse.toggle(True) mouse.move(absSecond.x, absSecond.y) mouse.toggle(False) mouse.move(lastX, lastY)
def isMouseAtExit(self): (x, y) = mouse.get_pos() #return x > self.gameOffset.x and x < self.gameOffset.x + GAME_SIZE.x and y > self.gameOffset.y and y < self.gameOffset.y + GAME_SIZE.y return x > self.gameOffset.x and x < self.gameOffset.x + 10 and y > self.gameOffset.y and y < self.gameOffset.y + 10
def get_type_pos(): input('请将鼠标光标移至将要填写的单元格位置(但不要点击),然后按Enter键……') return mouse.get_pos()
import sys import win32gui import win32con from PIL import ImageGrab from win32con import NULL game_hwnd= win32gui.FindWindow(None,"Windows PowerShell ISE") print game_hwnd win32gui.ShowWindow(game_hwnd, win32con.SW_RESTORE) # 强行显示界面后才好截图 win32gui.SetForegroundWindow(game_hwnd) # 将游戏窗口提到最前 # 裁剪得到全图 game_rect = win32gui.GetWindowRect(game_hwnd) from autopy import mouse print mouse.get_pos() src_image = ImageGrab.grab((game_rect[0] + 9, game_rect[1] + 190, game_rect[2] - 9, game_rect[1] + 190 + 450)) # src_image.show() # 分别裁剪左右内容图片 left_box = (9, 0, 500, 450) right_box = (517, 0, 517 + 500, 450) image_left = src_image.crop(left_box) image_right = src_image.crop(right_box) # image_left.show() # image_right.show() src_image.crop() # sys.path.append('.') # addr=r'D:\test.jpeg' # from PIL import ImageGrab
def dataReceived(self, data): #print "datareceived", data while data: try: decode, index = json_decode(data) except ValueError: # something went wrong.. FIXME return data = data[index:] if not isinstance(decode, dict): # something went wrong, gtfo for now, FIXME return command = decode.get('command') if command == 'mouse': pos = mouse.get_pos() action = decode.get('action') if action == 'click': for i in range(decode.get('n') or 1): mouse.click(BUTTONS[decode.get('b') - 1]) elif action == 'move': try: mouse.move(pos[0] + decode.get('dx'), pos[1] + decode.get('dy')) except ValueError: pass elif action == 'press': mouse.toggle(True, BUTTONS[decode.get('b') - 1]) elif action == 'release': mouse.toggle(False, BUTTONS[decode.get('b') - 1]) elif command == 'type': key.type_string(decode['string']) elif command == 'press_key': key.toggle(getattr(key, 'K_' + decode['key'].upper()), True) elif command == 'release_key': key.toggle(getattr(key, 'K_' + decode['key'].upper()), False) elif command == 'kill': self.kill_app(decode['uid']) elif command == 'capture': pos = mouse.get_pos() size = decode.get('size') maxx, maxy = screen.get_size() rect = (( max(0, min((pos[0] - size[0] / 2), maxx - size[0])), max(0, min((pos[1] - size[1] / 2), maxy - size[1])) ), (size[0], size[1])) try: bitmap.capture_screen(rect).save('tmp.png') except ValueError: return self.send(mouse_pos=(pos[0] - rect[0][0], pos[1] - rect[0][1])) #print "sending capture" self.send_image('tmp.png') elif decode.get('run') in zip(*self.commands)[0]: self.execute(decode.get('run'), decode.get('arguments'))
def _is_mouse_on_the_right(self): screen_resolution_x = screen.get_size()[0] mouse_pos_x = mouse.get_pos()[0] return mouse_pos_x >= screen_resolution_x / 2 /2