def scroll(self, pos, direction="vertical", duration=0.5, steps=5): if direction is "horizontal": raise ValueError( "Windows does not support horizontal scrolling currently") if direction is not 'vertical': raise ValueError( 'Argument `direction` should be "vertical". Got {}'.format(repr(direction))) set_foreground_window(self.window) pos = list(pos) pos[0] = pos[0] + self.monitor["left"] pos[1] = pos[1] + self.monitor["top"] pos = tuple(pos) coords = get_action_pos(self.window, pos) interval = float(duration) / (abs(steps) + 1) if steps < 0: for i in range(0, abs(steps)): time.sleep(interval) mouse.scroll(coords=coords, wheel_dist=1) else: for i in range(0, abs(steps)): time.sleep(interval) mouse.scroll(coords=coords, wheel_dist=-1)
def set_message_position(self): x = self.message.rectangle().left y = self.message.rectangle().top if not self.flag_5g: mouse.scroll(coords=(x + 100, y + 70), wheel_dist=8) mouse.click(coords=(x + 100, y + 70)) else: mouse.scroll(coords=(x + 65, y + 145), wheel_dist=8) mouse.scroll(coords=(x + 65, y + 145), wheel_dist=8) mouse.click(coords=(x + 65, y + 145))
import time # 选择单元结构 # time.sleep(5) # k = PyKeyboard() # k.press_key(k.shift_key) # # # 鼠标长按 # mouse.press(coords=(345,167)) # # time.sleep(2) # # # 释放鼠标位置 # mouse.release(coords=(1488,727)) # # k.release_key(k.shift_key) send_keys('{ENTER}') # 使用Ctrl+A ,Ctrl+C # 鼠标点击操作,可以修改coords来指定点击位置 mouse.click(button='left', coords=(0, 0)) # 鼠标双击操作,可以修改coords来指定双击位置 mouse.double_click(button='left', coords=(0, 0)) # 移动鼠标,可以修改coords使鼠标移动到指定位置 mouse.move(coords=(0, 0)) # 鼠标右键点击,可以修改coords来指定右键点击位置 mouse.right_click(coords=(0, 0)) # 鼠标滚动操作,可以修改coords来指定滚动位置,修改wheel_dist来指定滚动距离 mouse.scroll(coords=(0, 0), wheel_dist=1)
def test_vertical_scroll_down(self): mouse.click(coords=(self.__get_pos(50))) mouse.scroll(self.__get_pos(50), -1) data = self.__get_text() self.assertTrue("DOWN" in data)
def test_vertical_scroll(self): mouse.scroll((self.__get_pos(50)), 5) mouse.scroll((self.__get_pos(50)), -5) data = self.__get_text() self.assertTrue("UP" in data) self.assertTrue("DOWN" in data)
WB.set_focus() WB.type_keys("^a" "{DELETE}" "1400") WLWB_OK =PM_dialog.window(auto_id=r"w_OK",class_name="Button") WLWB_OK.draw_outline(colour="red") WLWB_OK.click_input() #快速分割 Seg_Seeds=PM_dialog.window(auto_id="segmentation_TakePixel") Seg_Seeds.draw_outline(colour="red") Seg_Seeds.click_input() Seed1_xy=(600,250) mouse.click(button="left",coords=Seed1_xy) time.sleep(1) mouse.scroll(coords=Seed1_xy, wheel_dist=1) time.sleep(1) Seed2_xy=(600,350) mouse.click(button="left",coords=Seed2_xy) Show=PM_dialog.window(auto_id="segmentation_Show",class_name="Button") Show.draw_outline(colour="red") Show.click_input() # 保存 # 需要处理2个弹出窗口: # 1.正在执行的窗口 MetroProBarWindow # 2.保存提示窗口 Popup= app["MetroProBarWindow"] Popup.wait("exists",timeout=3, retry_interval=1) print("正在执行中.......") Popup.wait_not("exists",timeout=60, retry_interval=1)
print("\x1B[" + "31;40mError\u2193\x1B[" + "0m") PrintException() raise e if module == "move": coord = GetParams("coord") try: coord = tuple(int(c) for c in coord.split(",")) print(coord) mouse.move(coords=coord) except Exception as e: print("\x1B[" + "31;40mError\u2193\x1B[" + "0m") PrintException() raise e if module == "scroll": coord = GetParams("coord") dist = GetParams("dist") try: coord = tuple([int(c) for c in coord.split(",")]) mouse.scroll(coords=coord, wheel_dist=int(dist)) except Exception as e: print("\x1B[" + "31;40mError\u2193\x1B[" + "0m") PrintException() raise e
import time #1-鼠标移动-move方法----move() # for i in range(10): # x=10*i # y=10*i # time.sleep(0.5) # #移动鼠标 # mouse.move(coords=(x,y)) #2-鼠标点击-click方法--button指定左击还是右击,coords指定鼠标点击的位置 #单击-指定位置,鼠标左击 # mouse.click(button='left',coords=(40,40)) #单击-指定位置,鼠标右击 mouse.click(button='right', coords=(40, 40)) #双击 mouse.double_click(button='left', coords=(40, 40)) #3-鼠标的按下与释放 #按下鼠标:press,将鼠标移动到(140,40)坐标处按下 mouse.press(button='left', coords=(140, 40)) #释放鼠标:repleace,将鼠标移动到(300,40)坐标处释放 mouse.release(button='left', coords=(300, 40)) #4-右键单击指定坐标 mouse.right_click(coords=(400, 400)) #5-鼠标中键单击指定坐标 mouse.wheel_click(coords=(400, 400)) #6-滚动鼠标 mouse.scroll(coords=(1200, 300), wheel_dist=-3)
def handle(self, command, *args, **kwargs): """ Execute a given command. :param command: string containing the command :param args: optional command args :param kwargs: optional command kwargs """ if command == "run": self.__execute(args) elif command == "dictate": dictation_recorder = CommandRecorder() filename = "dictation.wav" log("Listening to dictation...") dictation_recorder.record_for_seconds(filename=filename, record_seconds=10) log("Dictation ended.") transcription = interpret_dication(filename) log("Transcription: ", transcription) remove(filename) elif command == "enter": SendKeys('{ENTER}') elif command == "home": SendKeys('{HOME}') elif command == "desktop": SendKeys('{LWIN}d') # does it work? elif command == "next_window": SendKeys('%{ESC}') elif command == "up": scroll(coords=GetCursorPos(), wheel_dist=7) elif command == "down": scroll(coords=GetCursorPos(), wheel_dist=-7) elif command == "select_all": SendKeys('^a') elif command == "copy": SendKeys('^c') elif command == "paste": SendKeys('^v') elif command == "save": SendKeys('^s') elif command == "undo": SendKeys('^z') elif command == "find": SendKeys('^f') keyword_recorder = CommandRecorder() filename = "keyword.wav" log("What to find?") keyword_recorder.record_for_seconds(filename=filename, record_seconds=2) keyword = interpret_dication(filename) log("Szukam ", keyword) SendKeys(keyword[1:len(keyword) - 1] + '{ENTER}', with_spaces=True) remove(filename) elif command == "google": # WIP app = Application(backend='uia') app.start(self.chrome_path + ' --force-renderer-accessibility https://www.google.com') keyword_recorder = CommandRecorder() filename = "keyword.wav" log("What to google?") keyword_recorder.record_for_seconds(filename=filename, record_seconds=3) keyword = interpret_dication(filename) log("Googling ", keyword) SendKeys(keyword[1:len(keyword)-1] + '{ENTER}', with_spaces=True) remove(filename) elif command == "youtube": app = Application(backend='uia') app.start(self.chrome_path + ' --force-renderer-accessibility https://www.youtube.com') elif command == "close": SendKeys('%{F4}') elif command == "end_commander": _exit(0) elif command == "yoda": app = Application(backend='uia') app.start(self.chrome_path + ' --force-renderer-accessibility https://youtu.be/bYRYHLUNEs4?t=18') elif command == "private_browsing": app = Application(backend='uia') app.start(self.chrome_path + ' --force-renderer-accessibility https://www.youtube.com/watch?v=x6QZn9xiuOE') SendKeys('^+n') SendKeys('chicks' + '{ENTER}', with_spaces=True) log("Have fun!") else: raise NotImplementedError('Unknown command!')