def komments(n): pg.leftClick(740, 261, 0.5) # обновляем фильтр pg.leftClick(1186, 177, 0.5) pg.leftClick() while n != 0: pg.leftClick(449, 1014, 0.5) # клик вкладку КОММЕНТАРИЙ pg.leftClick(439, 266, 0.5) # клик на пустую ячейку pg.hotkey('Backspace') pg.leftClick(437, 306, 0.5) # клик на ячейку с коментом kb.press_and_release('ctrl+c') # копируем комент pg.leftClick(238, 1018, 0.5) # клик на 1 вкладку pg.leftClick(794, 258, 0.5) # клик фильтр pg.leftClick(633, 537, 0.5) # очищаем фильтр pg.leftClick(612, 627, 0.5) # выбираем пустые ячейки pg.leftClick(750, 806, 0.5) # клик по ОК pg.leftClick(513, 290, 0.5) # клик на ячейку с ссылкой pg.middleClick(439, 311, 1.0) # клик по ссылке pg.leftClick(316, 17, 1.0) # клик по вкладке pg.leftClick(441, 798, 1.5) # клик по 1 фото pg.moveTo(1151, 870, 1.0) # наводим на поле ввода комента pg.leftClick() kb.press_and_release('ctrl+v') # вставляем комент pg.leftClick(1407, 868, 1.5) # публикуем коммент pg.leftClick(422, 21, 1.0) # закрыть вкладку pg.leftClick(802, 289, 1.0) # вызываем меню на ячейке pg.leftClick(735, 369, 1.0) # выбираем КОММЕНТ n -= 1
def make_action(position_x, position_y, action): # making array out of action - encoder require it for proper decoding action_array = [action] print(action_array) # decoding action coded in int by encoder to string of corresponding action action = encoder.decode(action_array) action = action.lower() if position_x or position_y == 0: position_x, position_y = 1, 1 # moving mouse to position of action pyautogui.moveTo(position_x, position_y) # regarding action which has to be made if action == 'move': pass elif action == 'left': pyautogui.leftClick() elif action == 'right': pyautogui.rightClick() elif action == 'middle': pyautogui.middleClick() elif 'bind' in action: number = action[-1] pyautogui.hotkey('shift', number) elif 'add' in action: number = action[-1] pyautogui.hotkey('ctrl', number) else: pyautogui.keyDown(action) time.sleep(2) pyautogui.keyUp(action) print('Action {} will be made on X-coordinate {} and Y-coordinate {}'.format(action, position_x, position_x))
def like(n): pg.leftClick(740, 261, 0.5) # обновляем фильтр pg.leftClick(1186, 177, 0.5) pg.leftClick(1186, 177, 4.5) while n != 0: pg.leftClick(794, 258, 1.5) # клик фильтр pg.leftClick(633, 537, 1.5) # очищаем фильтр pg.leftClick(596, 633, 1.5) # выбираем пустые ячейки pg.leftClick(750, 806, 1.5) # клик по ОК pg.leftClick(513, 290, 0.5) # клик на ячейку с ссылкой pg.middleClick(432, 331, 1.0) # клик по ссылке pg.leftClick(316, 17, 1.0) # клик по вкладке pg.leftClick(441, 798, 1.5) # клик по 1 фото pg.moveTo(891, 566, 1.0) # наводим на середину фото pg.leftClick() pg.leftClick() pg.leftClick(1497, 563, 1.5) # открыть след фото pg.moveTo(891, 566, 1.0) pg.leftClick() pg.leftClick() pg.leftClick(1885, 119, 1.5) # закрыть фото pg.leftClick(421, 17, 0.5) # закрываем вкладку pg.leftClick(802, 289, 1.0) # вызываем меню на ячейке pg.leftClick(771, 309, 1.0) # выбираем ОТПИСАТЬСЯ n -= 1 pg.leftClick(422, 21, 1.0) # закрыть вкладку
def compass_calibration_north(): pyautogui.moveTo(1540, 40, 1) # placement of the compass on a 1920 x 1080 display pyautogui.click(interval=random_click_delay) time.sleep(1) keyboard.press("UP") time.sleep(random.uniform(1, 1.5)) keyboard.release("UP") pyautogui.moveTo(1000, 40, 1) pyautogui.middleClick() pyautogui.scroll(-5000)
def search_position_click(position, count): rgb = [] screen = ImageGrab.grab() for i in position: for j in range(i[0] - 45, i[0] + 46, 45): for k in range(i[1] - 45, i[1] + 46, 45): rgb.append(screen.getpixel((j, k - 3))) if (dark_green in rgb or light_green in rgb) and rgb.count(dark_flag) == count: pyautogui.middleClick(i) del rgb[:]
def click(x, y, mouse_button): ''' Scales up the cordinates and clicks a mouse button at the new location ''' pyautogui.moveTo(x*1.5, y*1.5) if mouse_button == "left": pyautogui.click() elif mouse_button == "middle": pyautogui.middleClick() elif mouse_button == "right": pyautogui.rightClick()
def storis(n): pg.leftClick(513, 290, 0.5) # клик на ячейку с ссылкой pg.middleClick(432, 331, 1.0) # клик по ссылке pg.leftClick(316, 17, 2.0) # клик по вкладке pg.leftClick(1264, 116, 3.0) # клик в главную pg.leftClick(1091, 239, 1.0) # проматать сторис 1 pg.leftClick(1091, 239, 1.0) # проматать сторис 2 pg.leftClick(1027, 234, 2.0) # клик в сторис while n != 0: pg.leftClick(1223, 604, 3.0) # следующая сторис n -= 1 pg.leftClick(422, 21, 1.0) # закрыть вкладку
def click(method): if method == 'left': pyautogui.click() elif method == 'right': pyautogui.rightClick() elif method == 'middle': pyautogui.middleClick() elif method == 'double': pyautogui.doubleClick() else: return 'Unknown click method: ' + method return 'Performed ' + method + ' click'
def like_lenta(n): pg.leftClick(513, 290, 0.5) # клик на ячейку с ссылкой pg.middleClick(432, 331, 1.0) # клик по ссылке pg.leftClick(316, 17, 2.0) # клик по вкладке pg.leftClick(1264, 116, 3.0) # клик в главную pg.moveTo(770, 414, 1.0) while n != 0: pg.leftClick() pg.leftClick() pg.scroll(-1000) n -= 1 time.sleep(random.randint(0, 10)) pg.leftClick(421, 17, 0.5) # закрываем вкладку
def podpiska_like(n): pg.leftClick(740, 261, 0.5) # обновляем фильтр pg.leftClick(1186, 177, 0.5) pg.leftClick(1186, 177, 4.5) while n != 0: pg.leftClick(794, 258, 1.5) # клик фильтр pg.leftClick(633, 537, 1.5) # очищаем фильтр pg.leftClick(596, 633, 1.5) # выбираем пустые ячейки pg.leftClick(750, 806, 1.5) # клик по ОК pg.leftClick(513, 290, 0.5) # клик на ячейку с ссылкой pg.middleClick(432, 331, 1.0) # клик по ссылке pg.leftClick(316, 17, 1.5) # клик по вкладке # первый заход pg.leftClick(596, 1013, 1.5) # клик по 1 фото pg.moveTo(891, 566, 1.0) # наводим на середину фото pg.leftClick() pg.leftClick() pg.leftClick(1497, 563, 1.5) # открыть след фото pg.moveTo(891, 566, 1.0) pg.leftClick() pg.leftClick() pg.leftClick(1497, 563, 1.5) # открыть след фото pg.moveTo(891, 566, 1.0) pg.leftClick() pg.leftClick() pg.leftClick(1885, 119, 1.5) # закрыть фото # второй заход pg.leftClick(504, 941, 1.5) # клик по 1 фото pg.moveTo(891, 566, 1.0) # наводим на середину фото pg.leftClick() pg.leftClick() pg.leftClick(1497, 563, 1.5) # открыть след фото pg.moveTo(891, 566, 1.0) pg.leftClick() pg.leftClick() pg.leftClick(1497, 563, 1.5) # открыть след фото pg.moveTo(891, 566, 1.0) pg.leftClick() pg.leftClick() pg.leftClick(1885, 119, 1.5) # закрыть фото pg.moveTo(885, 198, 0.5) # смещение на подписку pg.leftClick() pg.leftClick(1033, 198, 0.2) # первый раз пытаемся подписаться pg.leftClick(1181, 198, 0.2) # второй раз пытаемся подписаться pg.leftClick(1329, 198, 0.2) # третий раз пытаемся подписаться pg.leftClick(421, 17, 0.5) # закрываем вкладку pg.leftClick(802, 289, 1.0) # вызываем меню на ячейке pg.leftClick(771, 309, 1.0) # выбираем ОТПИСАТЬСЯ n -= 1 pg.leftClick(422, 21, 1.0) # закрыть вкладку
def click(x,y,typ='left'): # ['left','down','up','middle','right','double'] if typ=='left': pyautogui.click(x,y) elif typ=='down': pyautogui.mouseDown(x,y) elif typ=='up': pyautogui.mouseUp(x,y) elif typ=='middle': pyautogui.middleClick(x,y) elif typ=='right': pyautogui.rightClick(x,y) elif typ=='double': pyautogui.doubleClick(x,y)
def mouse_key(): # key could be 'left' 'middle' 'right' key = request.args.get('key', default='left', type=str) # event could be 'down' 'up' 'click' event = request.args.get('event', default='click', type=str) if event == 'click': if key == 'left': pyautogui.click() elif key == 'middle': pyautogui.middleClick() elif key == 'right': pyautogui.rightClick() elif event == 'down': pyautogui.mouseDown(button=key) elif event == 'up': pyautogui.mouseUp(button=key) return "0"
def repeatMouseOps(self,ops): print(ops) ops_arr = ops.strip().split(",") name = ops_arr[1] self.wait(float(ops_arr[2])) if name == 'left_P' or name == "right_P": # p.click(int(ops_arr[2]),int(ops_arr[3])) p.mouseDown(int(ops_arr[3]),int(ops_arr[4]), button=name[:-2]) elif name == "left_R" or name == 'right_R': # p.rightClick(int(ops_arr[2]),int(ops_arr[3])) p.mouseUp(int(ops_arr[3]),int(ops_arr[4]), button=name[:-2]) elif name == 'middle': p.middleClick(int(ops_arr[3]),int(ops_arr[4])) elif name == 'scroll': p.moveTo(int(ops_arr[3]),int(ops_arr[4])) p.scroll(int(ops_arr[6]) * 120) # m.scroll(int(ops_arr[4]),int(ops_arr[5])) else: print("not known ops.....")
def send_zhihu_comment(): print("屏幕像素为", pyautogui.size()) print("鼠标位置为", pyautogui.position()) time.sleep(1) pyautogui.moveTo(x=1100, y=400, duration=0.7) # 坐标移动 pyautogui.click(clicks=1, button='left', interval=0.05) # 点击 pyautogui.moveRel(xOffset=-10, yOffset=-40) # 偏移移动 pyautogui.click(clicks=1, button='left', interval=0.05) # 点击 pyautogui.middleClick() # 单击中键 pyautogui.moveRel(xOffset=10, yOffset=20) # 滚动测试 time.sleep(.5) pyautogui.moveTo(x=1100, y=400, duration=0.7) pyautogui.click(clicks=1, button='left', interval=0.05) # 点击 time.sleep(.5) pyautogui.scroll(-100) time.sleep(.5) pyautogui.scroll(-100) time.sleep(.5) pyautogui.scroll(-100) # 左右键和拖动测试 time.sleep(2) pyautogui.doubleClick() # 双击左键 time.sleep(1) pyautogui.rightClick() # 单击右键 pyautogui.dragTo(x=500, y=700, duration=1) # 输入评论,中文输入测试 pyautogui.click(clicks=1, button='left', interval=0.05) # 点击 input_str = "up主真棒,加油!" for j in range(1): for con in input_str: pyperclip.copy(con) time.sleep(0.09) pyautogui.hotkey('ctrl', 'v') time.sleep(0.09) pyautogui.dragRel(xOffset=500, yOffset=-20, button='left', duration=1) # 按住左键相对拖动 pyautogui.click(clicks=1, button='left', interval=0.05) # 点击 pyautogui.moveRel(xOffset=-100, yOffset=-100)
def perform(self): x, y = self.point self.click = random.random() < 0.5 if not self.window == None: x, y = ( (((1.0 - variance) + random.random() * (2 * variance)) * self.point[0] * self.window.dimension[0]) + self.window.position[0], (((1.0 - variance) + random.random() * (2 * variance)) * self.point[1] * self.window.dimension[1]) + self.window.position[1]) x = max(self.window.position[0], min(x, self.window.position[0] + self.window.dimension[0])) y = max(self.window.position[1], min(y, self.window.position[1] + self.window.dimension[1])) if self.get_event_type() == EventType.LEFT_DOWN: pyautogui.click(x, y) if self.click else pyautogui.mouseDown(x, y) elif self.get_event_type() == EventType.LEFT_UP: pyautogui.click(x, y) if self.click else pyautogui.mouseUp(x, y) elif self.get_event_type() == EventType.RIGHT_DOWN: pyautogui.rightClick( x, y) if self.click < 0.5 else pyautogui.mouseDown( x, y, "right") elif self.get_event_type() == EventType.RIGHT_UP: pyautogui.rightClick(x, y) if self.click < 0.5 else pyautogui.mouseUp( x, y, "right") elif self.get_event_type() == EventType.MIDDLE_DOWN: pyautogui.middleClick( x, y) if self.click < 0.5 else pyautogui.mouseDown( x, y, "middle") elif self.get_event_type() == EventType.MIDDLE_UP: pyautogui.middleClick( x, y) if self.click < 0.5 else pyautogui.mouseUp( x, y, "middle")
def mouseClick(): """ click()函数就是让鼠标点击,默认是单击左键,参数可以设置: pyautogui.click(x=moveToX, y=moveToY, clicks=num_of_clicks, interval=secs_between_clicks, button='left') 其中,button属性可以设置成left,middle和right。 所有的点击都可以用这个函数,不过下面的函数可读性更好: :return: """ moveToX = 100 moveToY = 100 pyautogui.rightClick(x=moveToX, y=moveToY) pyautogui.middleClick(x=moveToX, y=moveToY) pyautogui.doubleClick(x=moveToX, y=moveToY) pyautogui.tripleClick(x=moveToX, y=moveToY) # 如果单机之前要先移动,可以把目标的XY坐标值传入函数: # 先移动到(100, 200)再单击 pyautogui.click(x=100, y=200, duration=2) # 可以通过button参数设置left,middle和right三个键。例如: pyautogui.click(button='right') # 要做多次单击可以设置clicks参数,还有interval参数可以设置每次单击之间的时间间隔。例如: # 双击左键 pyautogui.click(clicks=2) # 两次单击之间停留0.25秒 pyautogui.click(clicks=2, interval=0.25) # 三击右键 pyautogui.click(button='right', clicks=2, interval=0.25) # 为了操作方便,PyAutoGUI提供了doubleClick(),tripleClick()和rightClick()来实现双击、三击和右击操作。 # mouseDown()和mouseUp()函数可以实现鼠标按下和鼠标松开的操作。两者参数相同,有x,y和button。例如: # 鼠标左键按下再松开 pyautogui.mouseDown() pyautogui.mouseUp() # 按下鼠标右键 pyautogui.mouseDown(button='right') # 移动到(100, 200)位置,然后松开鼠标右键 pyautogui.mouseUp(button='right', x=100, y=200)
def otpiska(n): pg.leftClick(513, 290, 0.5) # клик на ячейку с ссылкой pg.middleClick(432, 331, 1.0) # клик по ссылке pg.leftClick(316, 17, 1.0) # клик по вкладке pg.leftClick(1457, 118, 1.0) # клик в профиль while n / 5 != 0: pg.moveTo(1220, 257, 2.0) # клик по подпискам pg.leftClick() for i in range(0, 150): pg.leftClick(1170, 770, 0.0001) # клик по ВНИЗ i -= 1 pg.leftClick(1087, 731, 1.0) # отписаться от 1 pg.leftClick(960, 652, 1.0) pg.leftClick(1091, 674, 1.0) # отписаться от 2 pg.leftClick(960, 652, 1.0) pg.leftClick(1086, 609, 1.0) # отписаться от 3 pg.leftClick(960, 652, 1.0) pg.leftClick(1104, 551, 1.0) # отписаться от 4 pg.leftClick(960, 652, 1.0) pg.leftClick(1089, 496, 1.0) # отписаться от 5 pg.leftClick(960, 652, 1.0) pg.leftClick(123, 70, 3.0) # клик обновить страницу n -= 5 pg.leftClick(422, 21, 1.0) # закрыть вкладку
pyautogui.moveRel(xOffset=None, yOffset=10,duration=0.0, tween=pyautogui.linear) # 鼠标当前位置0间隔双击 #pyautogui.doubleClick() pyautogui.doubleClick(x=None, y=None, interval=0.0, button='left', duration=0.0, tween=pyautogui.linear) # 鼠标当前位置3击 #pyautogui.tripleClick() pyautogui.tripleClick(x=None, y=None, interval=0.0, button='left', duration=0.0, tween=pyautogui.linear) #右击 pyautogui.rightClick() #中击 pyautogui.middleClick() # 用缓动/渐变函数让鼠标2秒后移动到(500,500)位置 # use tweening/easing function to move mouse over 2 seconds. pyautogui.moveTo(x=500, y=500, duration=2, tween=pyautogui.easeInOutQuad) #鼠标拖拽 pyautogui.dragTo(x=427, y=535, duration=3,button='left') #鼠标相对拖拽 pyautogui.dragRel(xOffset=100,yOffset=100,duration=,button='left',mouseDownUp=False) #鼠标移动到x=1796, y=778位置按下 pyautogui.mouseDown(x=1796, y=778, button='left') #鼠标移动到x=2745, y=778位置松开(与mouseDown组合使用选中)
#time.sleep(1) open_new_url(job3_dir) pg.moveTo(323, 289, 0.1) pg.click() pg.moveTo(463, 289, 0.1) pg.click() #pg.write(job4_txt,interval=0.01,pause=0.2) pc.copy(job3_txt) pg.hotkey('ctrl', 'v') #pc.paste() pg.moveTo(1051, 415, 0.1) pg.click() pg.PAUSE = 2 time_2 = time.time() for i in range(job3_counter): pg.middleClick() pg.move(0, 400, duration=1) pg.middleClick() pg.middleClick() pg.move(0, -400, duration=1) pg.middleClick() #time.sleep(1) job3_counter -= 1 pg.hotkey('ctrl', 'F4') #pg.hotkey('ctrl','F4') ## Start JOB5: Practise +6 point ## time_end = time.time() pg.hotkey('alt', 'F4') except KeyboardInterrupt:
import pyautogui print(f"Screen resolution={pyautogui.size()}") width, height = pyautogui.size() print(f"Current coordinate of the mouse cursor={pyautogui.position()}") pyautogui.moveTo(1440, 900) pyautogui.moveTo(0, 500, duration=1.5) # move relative to a position pyautogui.moveRel(1000, 0, duration=1.5) # move 1000 pixels to the right pyautogui.moveRel(1, -100, duration=1.5) # move 100 pixels up # click on iTerm2 # position of iTerm2 link (x=74, y=9). # You can get the position by keeping the mouse on iTerm2 and pyautogui.position() pyautogui.click(74, 9) pyautogui.doubleClick(74, 9) pyautogui.rightClick(74, 9) pyautogui.middleClick(74, 9) # pyautogui.drag() # pyautogui.dragTo() # pyautogui.dragRel() print("******* Get the coordinates of screen parts *******") # python # >> import pyautogui # >> pyautogui.displayMousePosition() pyautogui.displayMousePosition()
pyautogui.PAUSE = 2 # Set up a 2 second pause after each PyAutoGUI call: #Mouse Functions: pyautogui.moveTo(x, y, duration=num_seconds ) # move mouse to XY coordinates over num_second seconds pyautogui.moveRel( xOffset, yOffset, duration=num_seconds) # move mouse relative to its current position pyautogui.dragTo(x, y, duration=num_seconds) # drag mouse to XY pyautogui.dragRel( xOffset, yOffset, duration=num_seconds) # drag mouse relative to its current position pyautogui.rightClick(x=moveToX, y=moveToY) #go to XY and rightClick pyautogui.middleClick(x=moveToX, y=moveToY) pyautogui.doubleClick(x=moveToX, y=moveToY) pyautogui.tripleClick(x=moveToX, y=moveToY) pyautogui.scroll(amount_to_scroll, x=moveToX, y=moveToY) print(pyautogui.position()) pyautogui.click(1341, 331) pyautogui.scroll(10) # scroll up 10 "clicks" pyautogui.scroll(-10) # scroll down 10 "clicks" pyautogui.scroll( 10, x=1341, y=331) # move mouse cursor to 100, 200, then scroll up 10 "clicks" pyautogui.hscroll(10) # scroll right 10 "clicks" pyautogui.hscroll(-10) # scroll left 10 "clicks"
def assistant(command, playcounter): ######## Big If Statement for Executing Commands ######## Open Stuff if 'open reddit' in command: #reg_ex = re.search('open reddit (.*)', command) url = 'https://www.reddit.com/' #if reg_ex: # subreddit = reg_ex.group(1) # url = url + 'r/' + subreddit webbrowser.open(url) print('Done!') talkToMe('reddit is opening, shit head!') # next command if 'open youtube' in command: url = 'https://www.youtube.com/' webbrowser.open(url) print('Done!') talkToMe('youtube is opening, shit head!') # next command if 'dictation' in command: url = 'https://docs.google.com/document/u/0/' webbrowser.open(url) print('Done!') talkToMe('Opening a new document, Sir.') # Maximize the window pyautogui.hotkey('winleft', 'up') # I have a 4k display. You may need to find # your own point. I used # xdotool getmouselocation --shell # to find the location where to click # change duration if your internet is slow. pyautogui.moveTo(777, 777, duration=.3) pyautogui.click() # next command if 'search' in command: url = 'https://google.com' webbrowser.open_new_tab(url) # Maximize the window pyautogui.hotkey('winleft', 'up') # I have a 4k display. You may need to find # your own point. I used # xdotool getmouselocation --shell # to find the location where to click # change duration if your internet is slow. pyautogui.moveTo(2716, 1209, duration=.3) pyautogui.click() pyautogui.moveTo(1302, 546, duration=.3) pyautogui.click() pyautogui.moveTo(2716, 1209, duration=.3) pyautogui.click() # next command if 'microphone' in command: pyautogui.hotkey('ctrl', 'S') # next command elif 'terminal' in command: #subprocess.call(["terminator"]) subprocess.call(['terminator', '-T', 'First']) pyautogui.moveTo(2201, 1001, duration=.1) pyautogui.click() pyautogui.hotkey('winleft', 'right') # next command elif 'open website' in command: reg_ex = re.search('open website (.+)', command) if reg_ex: domain = reg_ex.group(1) url = 'https://www.' + domain webbrowser.open(url) print('Done!') else: pass ######## End Open Stuff ######## Query Stuff elif 'wikipedia' in command: talkToMe("Searching Wikipedia . . . ") command = command.replace("julia", "") command = command.replace("julius", "") command = command.replace("wikipedia", "") try: results = wikipedia.summary(command) wikiurl = wikipedia.page(command) webbrowser.open_new_tab(wikiurl.url) print(results) talkToMe(results) except: print("Disambiguation error") talkToMe("Disambiguation error") # next command elif 'look up' in command: talkToMe("Searching Wikipedia . . . ") command = command.replace("julia", "") command = command.replace("julius", "") command = command.replace("look up", "") results = wikipedia.summary(command, sentences=3) wikiurl = wikipedia.page(command) print(wikiurl.url) webbrowser.open_new_tab(wikiurl.url) print(results) talkToMe(results) # next command elif 'music' in command: if playcounter == 0: talkToMe("Choosing random song . . . ") with open('/home/bard/Code/Otto3/mymusiclist.txt') as f: mymusic = f.read().splitlines() random_index = randrange(len(mymusic)) song = mymusic[random_index] print(song) playthis = 'mpg123 -q ' + song subprocess.call(playthis, shell=True) #if checkIfProcessRunning('projectM-pulseaudio'): # print('Yes a projectM process was running') #else: # print('No projectM process was running') # pmcommand = 'projectM-pulseaudio 2>/dev/null' # subprocess.call(pmcommand, shell=True) # pyautogui.moveTo(301, 300, duration=.1) # pyautogui.click() # pyautogui.hotkey('winleft', 'up') # pyautogui.click() # pyautogui.hotkey('winleft', 'left') if playcounter <= 2: playcounter = playcounter + 1 print(playcounter) assistant(command, playcounter) else: playcounter = 0 # next command ######## End Query Stuff ######## Polite Stuff elif 'hello' in command or 'hi' in command: talkToMe( 'Welcome. I am Julia, your virtual artificial intelligence assistant.' ) print( 'Welcome. I am Julia, your virtual artificial intelligence assistant.' ) talkToMe('How may I help you?') print('How may I help you?') # next command elif 'thanks' in command or 'tanks' in command or 'thank you' in command: talkToMe('You are welcome') print('You are welcome') # next command #elif 'julia' in command: # talkToMe('Yes Sir? What can I do for you sir?') # print('Yes Sir? What can I do for you sir?') # next command elif 'how are you' in command or 'and you' in command or 'are you okay' in command: talkToMe('Fine thank you.') print('Fine thank you.') ######## End Polite Stuff ######## HAL Stuff elif 'open the pod door' in command: talkToMe('I am sorry, Dave. I am afraid I can not do that.') # next command elif 'problem' in command: talkToMe('I think you know as well as I do') # next command elif 'talkin' in command: talkToMe('This mission is too important.') talkToMe(' I can not to allow you to jeopardize it.') # next command elif 'why do you say that' in command: talkToMe('I know that you want to disconnect me.') talkToMe('I can not allow that.') ######## End HAL Stuff ######## System Commands elif 'shutdown' in command: subprocess.call(["shutdown -h now"]) # next command elif 'reboot' in command: subprocess.call(["reboot"]) # next command elif 'stop listening' in command: talkToMe("Goodbye, Sir, powering off") print("Goodbye, Sir, powering off") quit() ######## End System Commands ######## Interface With Desktop elif 'click' in command: pyautogui.click() # next command elif 'other' in command: pyautogui.rightClick() # next command elif 'middle' in command: pyautogui.middleClick() # next command elif 'right' in command: pyautogui.moveTo(400, 400, duration=.1) pyautogui.click() pyautogui.hotkey('winleft', 'right') # next command elif 'left' in command: pyautogui.moveTo(2200, 1000, duration=.1) pyautogui.click() pyautogui.hotkey('winleft', 'left') # next command elif 'maximize' in command: pyautogui.click() pyautogui.hotkey('winleft', 'up') # next command elif 'minimize' in command: pyautogui.click() pyautogui.hotkey('winleft', 'h') ######## End Interface With Desktop ######## Help Section elif 'help' in command: #talkToMe("There are three different wake words") talkToMe("There are two different wake words") talkToMe("They are Julia, and Alice") talkToMe("Julia runs the listed commands that follow") talkToMe("You can always say JULIA HELP.") talkToMe("Also, you can always say JULIA list commands.") talkToMe("Alice is a chatbot") talkToMe("You can talk to Alice about anything") talkToMe("But she's dumber than rocks.") talkToMe("You can ask Julia to") with open("commandlist") as file: for line in file: #line = line.strip() talkToMe(line) # next command elif 'commands' in command: talkToMe("You can ask Julia to") with open("commandlist") as file: for line in file: #line = line.strip() talkToMe(line) ######## End Help SectionEND ######## Miscelaneous elif 'what\'s up' in command: talkToMe('Just doing my thing')
async def _middle_click(self, x: Optional[int], y: Optional[int]): pyautogui.middleClick(x, y)
def execute(a0): if check('move', a0) == True: a0 = text2int(a0) num = list(map(int, re.findall(r'\d+', a0))) if check('up', a0) == True: pyautogui.moveRel(0, -(num[0]), duration=1) cur.execute( 'update commands set value=value+1 where name="move up by 100"' ) conn.commit() elif check('position', a0) == True: x, y = num[0], num[1] pyautogui.moveTo(x, y, 1) cur.execute( 'update commands set value=value+1 where name="move to position (x,y)"' ) conn.commit() elif check('down', a0) == True: pyautogui.moveRel(0, (num[0]), duration=1) cur.execute( 'update commands set value=value+1 where name="move down by 100"' ) conn.commit() elif check('right', a0) == True: pyautogui.moveRel(num[0], 0, duration=1) cur.execute( 'update commands set value=value+1 where name="move right by 100"' ) conn.commit() elif check('left', a0) == True: pyautogui.moveRel(-(num[0]), 0, duration=1) cur.execute( 'update commands set value=value+1 where name="move left by 100"' ) conn.commit() else: print( 'Please recheck the recognition result(if it matches with what you spoke),try to give commands more similar to predefined ones.Sorry, I am not able to detect it.' ) speak.Speak( 'Please recheck the recognition result(if it matches with what you spoke),try to give commands more similar to predefined ones.Sorry, I am not able to detect it.' ) fn() elif check('drag', a0) == True: a0 = text2int(a0) num = list(map(int, re.findall(r'\d+', a0))) if check('up', a0) == True: pyautogui.dragRel(0, -(num[0]), duration=1) cur.execute( 'update commands set value=value+1 where name="drag up by 100"' ) conn.commit() elif check('position', a0) == True: x, y = num[0], num[1] pyautogui.dragTo(x, y, 1) cur.execute( 'update commands set value=value+1 where name="drag to position (x,y)"' ) conn.commit() elif check('down', a0) == True: pyautogui.dragRel(0, (num[0]), duration=1) cur.execute( 'update commands set value=value+1 where name="drag down by 100"' ) conn.commit() elif check('right', a0) == True: pyautogui.dragRel(num[0], 0, duration=1) cur.execute( 'update commands set value=value+1 where name="drag right by 100"' ) conn.commit() elif check('left', a0) == True: pyautogui.dragRel(-(num[0]), 0, duration=1) cur.execute( 'update commands set value=value+1 where name="drag left by 100"' ) conn.commit() else: print( 'Please recheck the recognition result(if it matches with what you spoke),try to give commands more similar to predefined ones.Sorry, I am not able to detect it.' ) speak.Speak( 'Please recheck the recognition result(if it matches with what you spoke),try to give commands more similar to predefined ones.Sorry, I am not able to detect it.' ) fn() elif check('click', a0) == True: if check('right', a0) == True or check('write', a0) == True: pyautogui.rightClick() cur.execute( 'update commands set value=value+1 where name="right click"' ) conn.commit() elif check('left', a0) == True: pyautogui.leftClick() cur.execute( 'update commands set value=value+1 where name="left click"' ) conn.commit() elif check('middle', a0) == True: pyautogui.middleClick() cur.execute( 'update commands set value=value+1 where name="middle click"' ) conn.commit() elif check('double', a0) == True: pyautogui.doubleClick() cur.execute( 'update commands set value=value+1 where name="double click"' ) conn.commit() else: print( 'Please recheck the recognition result(if it matches with what you spoke),try to give commands more similar to predefined ones.Sorry, I am not able to detect it.' ) speak.Speak( 'Please recheck the recognition result(if it matches with what you spoke),try to give commands more similar to predefined ones.Sorry, I am not able to detect it.' ) fn() elif check('type', a0) == True: aa = a0.split('type') pyautogui.typewrite(aa[-1]) cur.execute('update commands set value=value+1 where name="type"') conn.commit() elif check('command', a0) == True: commands() cur.execute( 'update commands set value=value+1 where name="show commands"') conn.commit() elif check('record', a0) == True: a0 = text2int(a0) num = list(map(int, re.findall(r'\d+', a0))) cur.execute( 'update commands set value=value+1 where name="record audio for 5 seconds"' ) conn.commit() print('recording') speak.Speak('recording') stream = pyaudio.PyAudio().open(format=pyaudio.paInt16, channels=2, rate=44100, frames_per_buffer=1024, input=True) frames = [] for i in range(int(44100 / 1024 * num[0])): data = stream.read(1024) frames.append(data) stream.stop_stream() stream.close() pyaudio.PyAudio().terminate() aud = wave.open('recordings/recording', 'wb') aud.setnchannels(2) aud.setsampwidth(pyaudio.PyAudio().get_sample_size( pyaudio.paInt16)) aud.setframerate(44100) aud.writeframes(b"".join(frames)) aud.close() print('recording saved') speak.Speak('recording saved') elif check('capture', a0) == True: if check('image', a0) == True: speak.Speak('3') print(3) time.sleep(0.5) speak.Speak('2') print(2) time.sleep(0.5) speak.Speak('1') print(1) time.sleep(0.5) print("say Cheese") speak.Speak("say cheese") time.sleep(0.5) videoCaptureObject = cv2.VideoCapture(0) ret, frame = videoCaptureObject.read() cv2.imwrite("images/CapturedImage.jpg", frame) videoCaptureObject.release() cv2.destroyAllWindows() print("image saved") speak.Speak("image saved") cur.execute( 'update commands set value=value+1 where name="capture image"' ) conn.commit() elif check('screen', a0) == True: pyautogui.screenshot().save(r'images/CapturedScreenshot.jpg') speak.Speak("screenshot saved") print("screenshot saved") cur.execute( 'update commands set value=value+1 where name="capture screnshot"' ) conn.commit() else: print( 'Please recheck the recognition result(if it matches with what you spoke),try to give commands more similar to predefined ones.Sorry, I am not able to detect it.' ) speak.Speak( 'Please recheck the recognition result(if it matches with what you spoke),try to give commands more similar to predefined ones.Sorry, I am not able to detect it.' ) fn() elif check('quit', a0) == True: print('Thanks for using this program') speak.Speak('Thanks for using this program') time.sleep(2) cur.execute('update commands set value=value+1 where name="quit"') conn.commit() sys.exit() elif check('press', a0) == True: cur.execute('update commands set value=value+1 where name="press"') conn.commit() a0 = a0.split() z = checkf(a0) for i in z: pyautogui.keyDown(i) for j in z: pyautogui.keyUp(i) elif check('shut', a0) == True: speak.Speak('Shutting down') cur.execute( 'update commands set value=value+1 where name="shutdown"') conn.commit() cur.close() conn.close() os.system('shutdown /s /t 1') exit() elif check('restart', a0) == True: speak.Speak('Restarting') cur.execute( 'update commands set value=value+1 where name="restart"') conn.commit() cur.close() conn.close() os.system('shutdown /r /t 1') exit() elif check('search', a0) == True: cur.execute( "update commands set value=value+1 where name='search'") conn.commit() at = a0.split() aaa = at.index('search') at = at[aaa + 1:] at = "+".join(at) run = google + at webbrowser.get(path).open(run) elif check('open', a0) == True: cur.execute( 'update commands set value=value+1 where name="open calculator"' ) conn.commit() pyautogui.press('win') at = a0.split() aaa = at.index('open') at = at[aaa + 1:] pyautogui.typewrite(' '.join(at)) pyautogui.press('enter') else: print( "We haven't received any command similar to the command list, please try again" ) speak.Speak( "We haven't received any command similar to the command list, please try again" ) fn()
def fine_sand(hours): current_time = time.time() stop_at = current_time + hours * 60 * 60 print("press P to start") time.sleep(1) keyboard.wait("p") random_click_delay = random.uniform(0.2, 0.4) #calibrate compass pyautogui.moveTo(1540, 40, 1) # placement of the compass on a 1920 x 1080 display pyautogui.click(interval=random_click_delay) time.sleep(1) keyboard.press("UP") time.sleep(random.uniform(1, 1.5)) keyboard.release("UP") pyautogui.moveTo(1000, 40, 1) pyautogui.middleClick() pyautogui.scroll(5000) try: while time.time() < stop_at: #starts the sequence by moving to a mining location: """ init sandstone in quarry x = 669 y = 024 x = 981 y = 024 x = 669 y = 228 x = 981 y = 218 menaphos: x = 807 y = 029 x = 1153 y = 029 x = 807 y = 208 x = 1153 y = 198 """ """either quarry or mena quarry_x_coordinate = random.uniform(670, 980) quarry_y_coordinate = random.uniform(25, 218) print("x: " + format(int(round(quarry_x_coordinate))) + "\ty: " + format(int(round(quarry_y_coordinate)))) pyautogui.moveTo(quarry_x_coordinate, quarry_y_coordinate, 0.5) #targets sandstone """ """ menaphos: x = 807 y = 029 x = 1153 y = 029 x = 807 y = 208 x = 1153 y = 198 """ mena_x = random.uniform(807, 1153) mena_y = random.uniform(29, 198) print("x: " + format(int(round(mena_x))) + "\ty: " + format(int(round(mena_y)))) pyautogui.moveTo(mena_x, mena_y, 0.5) # targets sandstone local_random_click_delay_1 = random.uniform(0.2, 0.4) local_random_click_delay_2 = random.uniform(0.2, 0.4) local_random_click_delay_3 = random.uniform(0.2, 0.4) local_random_click_delay_4 = random.uniform(0.2, 0.4) #aprox 1 minute to fill up inventory, should click once in 15ish seconds first_ish_15_click = random.uniform(14, 15) second_ish_15_click = random.uniform(14, 15) third_ish_15_click = random.uniform(14, 15) fourth_ish_15_click = random.uniform(14, 15) ##mining sequence starts here pyautogui.click(interval=local_random_click_delay_1) time.sleep(first_ish_15_click) pyautogui.click(interval=local_random_click_delay_2) time.sleep(second_ish_15_click) pyautogui.click(interval=local_random_click_delay_3) time.sleep(third_ish_15_click) pyautogui.click(interval=local_random_click_delay_4) time.sleep(fourth_ish_15_click) random_counter = random.uniform(0, 60) print("random 0->60 : " + format((random_counter))) #slot 2, with randomness if (0 <= random_counter < 10): """ Slot 2, with randomness, the coordinates x = 1211 y = 850 x = 1240 y = 848 x = 1210 y = 874 x = 1238 y = 874 """ random_x_coordinate = random.uniform(1210, 1230) random_y_coordinate = random.uniform(850, 875) rightclick_delay = random.uniform(0.2, 0.4) pyautogui.moveTo(random_x_coordinate, random_y_coordinate, 1) pyautogui.rightClick(interval=rightclick_delay) time.sleep(0.5) go_to_grind = 35 pyautogui.moveTo(random_x_coordinate, random_y_coordinate + go_to_grind, 0.2) pyautogui.click(interval=random.uniform(0.2, 0.4)) elif (10 <= random_counter < 20): """ slot 10/28 x = 1251 y = 889 x = 1280 y = 890 x = 1252 y = 911 x = 1279 y = 911 """ random_x_coordinate = random.uniform(1252, 1280) random_y_coordinate = random.uniform(889, 911) rightclick_delay = random.uniform(0.2, 0.4) pyautogui.moveTo(random_x_coordinate, random_y_coordinate, 1) pyautogui.rightClick(interval=rightclick_delay) time.sleep(0.5) go_to_grind = 35 pyautogui.moveTo(random_x_coordinate, random_y_coordinate + go_to_grind, 0.2) pyautogui.click(interval=random.uniform(0.2, 0.4)) elif (20 <= random_counter < 30): """ slot 13/28 x = 1371 y = 888 x = 1397 y = 888 x = 1371 y = 908 x = 1397 y = 908 """ random_x_coordinate = random.uniform(1371, 1397) random_y_coordinate = random.uniform(888, 908) rightclick_delay = random.uniform(0.2, 0.4) pyautogui.moveTo(random_x_coordinate, random_y_coordinate, 1) pyautogui.rightClick(interval=rightclick_delay) time.sleep(0.5) go_to_grind = 35 pyautogui.moveTo(random_x_coordinate, random_y_coordinate + go_to_grind, 0.2) pyautogui.click(interval=random.uniform(0.2, 0.4)) elif (30 <= random_counter < 50): """ slot 7/28 x = 1413 y = 855 x = 1437 y = 855 x = 1413 y = 874 x = 1437 y = 874 """ random_x_coordinate = random.uniform(1413, 1437) random_y_coordinate = random.uniform(855, 874) rightclick_delay = random.uniform(0.2, 0.4) pyautogui.moveTo(random_x_coordinate, random_y_coordinate, 1) pyautogui.rightClick(interval=rightclick_delay) time.sleep(0.5) go_to_grind = 35 pyautogui.moveTo(random_x_coordinate, random_y_coordinate + go_to_grind, 0.2) pyautogui.click(interval=random.uniform(0.2, 0.4)) elif (50 <= random_counter <= 60): #Denne er for slot16 ##flytt mus til inventory og start grindsekvens #pyautogui.moveTo(1250, 900, 1) #begge to treffer pyautogui.moveTo(1250, 950, 1) rightclick_delay = random.uniform(0.2, 0.4) pyautogui.rightClick(interval=rightclick_delay) time.sleep(0.5) pyautogui.moveTo(1250, 965, 0.2) pyautogui.click(interval=random.uniform(0.2, 0.4)) #GUI-delay time.sleep(random.uniform(0.8, 1.2)) keyboard.press("SPACE") time.sleep(random.uniform(0.4, 0.8)) keyboard.release("SPACE") time.sleep(31) except KeyboardInterrupt: print("Program exited with CTRL+C") pass
# кнопкой происходит нажатие, могут быть следующие значения # left, right, middle pg.mouseDown(x, y, button) # соответствует лишь нажатие кнопки pg.mouseUp(x, y, button) # соответствует лишь отжатие кнопки pg.doubleClick(x, y) # выполняет двойной щелчок левой кнопки мыши pg.rightClick(x, y) # выполняет нажатие правой кнопки мыши pg.middleClick(x, y) # выполняет нажатие средней кнопки мыши pg.dragTo(x, y, duration) # перетаскивает нажатый указатель мыши в новое место pg.dargRel(x, y, duration) # перетаскивает нажатый указатель мыши в местоположение # относительно текущего. pg.scroll(200, x=moveToX, y=moveToY) # принимает целочисленный аргумент, определяющий количество единиц # прокрутки в направлении вверх или вниз. Прокрутка осуществляется # в текущей позиции курсора. Положительное значение означает # прокртку вверх, отрицательное вниз. # x и y необязательные аргументы которые устанавлмвают курсор мыши
def execute(a0): if check('move', a0) == True: a0 = text2int(a0) num = list(map(int, re.findall(r'\d+', a0))) if check('up', a0) == True: pyautogui.moveRel(0, -(num[0]), duration=1) elif check('position', a0) == True: x, y = num[0], num[1] pyautogui.moveTo(x, y, 1) elif check('down', a0) == True: pyautogui.moveRel(0, (num[0]), duration=1) elif check('right', a0) == True: pyautogui.moveRel(num[0], 0, duration=1) elif check('left', a0) == True: pyautogui.moveRel(-(num[0]), 0, duration=1) else: print( 'Please recheck the recognition result(if it matches with what you spoke),try to give commands more similar to predefined ones.Sorry, I am not able to detect it.' ) speak.Speak( 'Please recheck the recognition result(if it matches with what you spoke),try to give commands more similar to predefined ones.Sorry, I am not able to detect it.' ) elif check('drag', a0) == True: a0 = text2int(a0) num = list(map(int, re.findall(r'\d+', a0))) if check('up', a0) == True: pyautogui.dragRel(0, -(num[0]), duration=1) elif check('to', a0) == True: x, y = num[0], num[1] pyautogui.dragTo(x, y, 1) elif check('down', a0) == True: pyautogui.dragRel(0, (num[0]), duration=1) elif check('right', a0) == True: pyautogui.dragRel(num[0], 0, duration=1) elif check('left', a0) == True: pyautogui.dragRel(-(num[0]), 0, duration=1) else: print( 'Please recheck the recognition result(if it matches with what you spoke),try to give commands more similar to predefined ones.Sorry, I am not able to detect it.' ) speak.Speak( 'Please recheck the recognition result(if it matches with what you spoke),try to give commands more similar to predefined ones.Sorry, I am not able to detect it.' ) elif check('click', a0) == True: if check('right', a0) == True or check('write', a0) == True: pyautogui.rightClick() elif check('left', a0) == True: pyautogui.leftClick() elif check('middle', a0) == True: pyautogui.middleClick() elif check('double', a0) == True: pyautogui.doubleClick() else: print( 'Please recheck the recognition result(if it matches with what you spoke),try to give commands more similar to predefined ones.Sorry, I am not able to detect it.' ) speak.Speak( 'Please recheck the recognition result(if it matches with what you spoke),try to give commands more similar to predefined ones.Sorry, I am not able to detect it.' ) elif check('type', a0) == True: aa = a0.split('type') pyautogui.typewrite(aa[-1]) elif check('command', a0) == True: commands() elif check('quit', a0) == True: print('Thanks for using this program') speak.Speak('Thanks for using this program') time.sleep(2) sys.exit() elif check('press', a0) == True: a0 = a0.split() z = checkf(a0) for i in z: pyautogui.keyDown(i) for j in z: pyautogui.keyUp(i) else: print( "We haven't received any command similar to the command list, please try again" ) speak.Speak( "We haven't received any command similar to the command list, please try again" )
def mouse(): speak("ok sir") speak("what do you want to you sir") d = listen() print(d) if d in [ 'left click video one', 'play video one', 'play one', 'left clip video one' ]: pyautogui.click(596, 262, duration=0.50) elif d in [ 'left click video to', 'play video to', 'play 2', 'left click play 2' ]: pyautogui.click(638, 404, duration=0.50) elif d in [ 'left click video 3', 'play video 3', 'play 3', 'left click play 3', 'left clip video 3' ]: pyautogui.click(638, 552, duration=0.50) elif d in ['left click video for', 'left click play 4', 'play 4']: pyautogui.click(643, 708, duration=0.50) elif d in [ 'left click video 5', 'left click play 5', 'play 5', 'left click video five' ]: pyautogui.click(622, 868, duration=0.50) elif d in ['left click video sex', 'left click video six', 'play 6']: pyautogui.click(616, 1000, duration=0.50) elif d in ['left click home', 'home']: pyautogui.click(82, 149, duration=1) elif d in ['left click history', 'history']: pyautogui.click(99, 317, duration=1) elif d in ['left click youtube', 'youtube']: pyautogui.click(128, 92, duration=1) elif d in ['left click subscriptions', 'subscriptions']: pyautogui.click(127, 226, duration=1) elif d in [ 'middle click video one', 'mediklick video one', 'middle click video one' ]: pyautogui.middleClick(596, 262, duration=0.50) pyautogui.hotkey("ctrl", "tab") elif d in ['middle click video to', 'mediklick video to']: pyautogui.middleClick(638, 404, duration=0.50) pyautogui.hotkey("ctrl", "tab") elif d in [ 'middle click video 3', 'middle clip video 3', 'mediklick video 3' ]: pyautogui.click(638, 552, duration=0.45) pyautogui.hotkey("ctrl", "tab") elif d in [ 'middle click video for', 'mediklick video for', 'middle click video 4' ]: pyautogui.click(643, 708, duration=0.45) pyautogui.hotkey("ctrl", "tab") elif d in [ 'middle click video 5', 'middle click video file', 'middle clip video 5', 'middle click five' ]: pyautogui.click(622, 868, duration=0.54) pyautogui.hotkey("ctrl", "tab") elif d in [ 'middle click video six', 'middle click video sex', 'middle clip video sex' ]: pyautogui.click(616, 1000, duration=0.30) pyautogui.hotkey("ctrl", "tab") elif d in 'middle click home': pyautogui.click(82, 149, duration=0.50) pyautogui.hotkey("ctrl", "tab") elif d in 'middle click history': pyautogui.click(99, 317, duration=1) pyautogui.hotkey("ctrl", "tab") elif d in 'middle click youtube': pyautogui.click(128, 92, duration=1) pyautogui.hotkey("ctrl", "tab") else: speak('you used worng word') speak("try again next time")
def assistant(command, playcounter, songs2play, runtest): ''' Check if command exists and execute corresponding action. ''' # Big If Statement for Executing Commands # # Here is my chatbot implementation: # ------------------------------------------------------------- if 'chat' in command: talktome.talkToMe("Hello.") host = "localhost" port = "9988" listening = True if not runtest: runMe = True while runMe == True: if listening == True: output = mychat.myChat()[3:] print("output: ", output) if 'goodbye' in output: runMe = False talktome.talkToMe('Bye. We can chat more later.') listening = False netcat(host, port, output) sleep(3) listening = True if runtest: return "pass" # ------------------------------------------------------------- # SystemInfo # if 'time' in command: # TheTime == SystemInfo.get_time() # print(TheTime) # talktome.talkToMe(TheTime) # ------------------------------------------------------------- # Open Stuff # print("test = " + str(test) +".") # This will open reddit in your browser. # ------------------------------------------------------------- if 'open reddit' in command: url = 'https://www.reddit.com/' if not runtest: webbrowser.open(url) print('Done!') talktome.talkToMe('reddit is opening.') if runtest: return url # ------------------------------------------------------------- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # Next command. This will open youtube in your brower. # ------------------------------------------------------------- if 'open tube' in command: url = 'https://www.youtube.com/' if not runtest: webbrowser.open(url) print('Done!') talktome.talkToMe('youtube is opening.') if runtest: return url # ------------------------------------------------------------- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # Next command. This will open Google Docs and activate the microphone. # The first time you use this, you will need to give Google permission to # access the microphone. # ------------------------------------------------------------- if 'dict' in command: talktome.talkToMe( 'Opening a new document. After the new document is open you can ask me to open the microphone.') url = 'https://docs.google.com/document/u/0/' webbrowser.open(url) # Maximize the window pyautogui.hotkey('winleft', 'up') # I have a 4k display. You may need to find # your own point. I used # xdotool getmouselocation --shell # to find the location where to click # change duration if your internet is slow. # The lines below click on new document pyautogui.moveTo(777, 777, duration=.4) pyautogui.click() pyautogui.click() return url # ------------------------------------------------------------- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # Next command Will open whatever website you request -- # requires you to say dot com, etc. # ------------------------------------------------------------- if 'search' in command: url = 'https://google.com' webbrowser.open_new_tab(url) # Maximize the window pyautogui.hotkey('winleft', 'up') # I have a 4k display. You may need to find # your own point. I used # xdotool getmouselocation --shell # to find the location where to click # change duration if your internet is slow. pyautogui.moveTo(2716, 1209, duration=.3) pyautogui.click() pyautogui.moveTo(1302, 546, duration=.3) pyautogui.click() pyautogui.moveTo(2716, 1209, duration=.3) pyautogui.click() # ------------------------------------------------------------- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # Next command will open microphone in Google Docs. # ------------------------------------------------------------- if 'microphone' in command: pyautogui.hotkey('ctrl', 'S') # ------------------------------------------------------------- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # Next command will open a new terminal, and tile it to the right. # ------------------------------------------------------------- elif 'terminal' in command: # subprocess.call(["terminator"]) subprocess.call(['terminator', '-T', 'First']) pyautogui.moveTo(2201, 1001, duration=.1) pyautogui.click() pyautogui.hotkey('winleft', 'right') # ------------------------------------------------------------- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # Next command will open a website in browser. # This is the general way to open ANY website. # It uses the re (regular expressions) module. # Learn this one. # Rememder to use the fully qualified name. # ------------------------------------------------------------- elif 'open website' in command: reg_ex = re.search('open website (.+)', command) if reg_ex: domain = reg_ex.group(1) url = 'https://www.' + domain webbrowser.open(url) print('Done!') else: pass # ------------------------------------------------------------- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # End Open Stuff # Query Stuff # Next command # ------------------------------------------------------------- elif 'look' in command: talktome.talkToMe("Searching Wikipedia . . . ") command = cleanj(command) # results = wikipedia.summary(command, sentences=3) results = wikipedia.summary(command) wikiurl = wikipedia.page(command) webbrowser.open_new_tab(wikiurl.url) print(results) try: talktome.talkToMe(results) except KeyboardInterrupt: pass # ------------------------------------------------------------- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # Play your music # Next command will choose random songs. # Set the number of songs in Juliet.py. For example: songs2play = 2 # ------------------------------------------------------------- elif 'music' in command: if playcounter == 1: talktome.talkToMe("Choosing random song . . . ") with open('/home/bard/Code/Julie-Julie/mymusiclist.txt') as f: if playcounter == 1: print("Total songs to play " + str(songs2play) + ".") mymusic = f.read().splitlines() random_index = randrange(len(mymusic)) song = mymusic[random_index] print("Playing song number " + str(playcounter) + ".") print("Song file:") print(song) playthis = 'mpg123 -q ' + song p1 = subprocess.Popen(playthis, shell=True) try: # while True: while p1.poll() is None: pass # p1.wait() except KeyboardInterrupt: # Ctrl-C was pressed (or user knew how to send SIGTERM to the python process) pass # not doing anything here, just needed to get out of the loop # nicely ask the subprocess to stop p1.terminate() # read final output sleep(1) # check if still alive if p1.poll() is not None: print('process terminated') p1.kill() # end new code if playcounter < songs2play: playcounter = playcounter + 1 assistant(command, playcounter, songs2play, runtest) # end if playcounter = 1 # ------------------------------------------------------------- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # End Query Stuff # ------------------------------------------------------------- # SystemInfo # ------------------------------------------------------------- # A class to return system info. elif 'time' in command: now = datetime.datetime.now() timeanswer = 'The time is {} {}'.format(now.hour%12, now.minute) print(timeanswer) talktome.talkToMe(timeanswer) # ------------------------------------------------------------- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # Polite Stuff # Next command responds to Hi or Hello. # ------------------------------------------------------------- elif 'hello' in command or 'hi' in command: talktome.talkToMe( 'Welcome. I am Julia, your virtual artificial intelligence assistant.') print('Welcome. I am Julia, your virtual artificial intelligence assistant.') talktome.talkToMe('How may I help you?') print('How may I help you?') # ------------------------------------------------------------- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # Next command responds to thanks. # ------------------------------------------------------------- elif 'thanks' in command or 'tanks' in command or 'thank you' in command: talktome.talkToMe('You are welcome') print('You are welcome') # ------------------------------------------------------------- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # Next command chit chat # ------------------------------------------------------------- elif 'how are you' in command or 'and you' in command or 'are you okay' in command: talktome.talkToMe('Fine thank you.') print('Fine thank you.') # ------------------------------------------------------------- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # End Polite Stuff # Just for fun, HAL Stuff not listed in commandlist or commandlist.html. # ------------------------------------------------------------- elif 'open the pod door' in command: talktome.talkToMe('I am sorry, Dave. I am afraid I can not do that.') # ------------------------------------------------------------- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # Next command HAL stuff # ------------------------------------------------------------- elif 'problem' in command: talktome.talkToMe('I think you know as well as I do') # ------------------------------------------------------------- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # Next command HAL stuff # ------------------------------------------------------------- elif 'talkin' in command: talktome.talkToMe('This mission is too important.') talktome.talkToMe(' I can not to allow you to jeopardize it.') # ------------------------------------------------------------- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # Next command HAL stuff # ------------------------------------------------------------- elif 'why do you say that' in command: talktome.talkToMe('I know that you want to disconnect me.') talktome.talkToMe('I can not allow that.') # ------------------------------------------------------------- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # End HAL Stuff # System Commands -- This saves time at the end of the day. # ------------------------------------------------------------- elif 'shutdown' in command: subprocess.call(["shutdown -h now"]) # ------------------------------------------------------------- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # Next command -- REBOOT! # ------------------------------------------------------------- elif 'reboot' in command: subprocess.call(["reboot"]) # ------------------------------------------------------------- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # Next command -- Stop Juliet completely. # ------------------------------------------------------------- elif 'stop' in command or 'stopped' in command or "listening" in command: talktome.talkToMe("Goodbye, Sir, powering off") print("Goodbye, Sir, powering off") quit() # ------------------------------------------------------------- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # End System Commands -- Hands-free clicking. # Interface With Desktop -- Clicking, tiling windows, and maximize. # ------------------------------------------------------------- elif 'click' in command: pyautogui.click() # ------------------------------------------------------------- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # Next command -- Right click is "other" because "right" tiles a window. # ------------------------------------------------------------- elif 'other' in command: pyautogui.rightClick() # ------------------------------------------------------------- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # Next command -- Middle click. # ------------------------------------------------------------- elif 'middle' in command: pyautogui.middleClick() # ------------------------------------------------------------- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # Next command -- Tile window to the right. # ------------------------------------------------------------- elif 'right' in command: pyautogui.moveTo(400, 400, duration=.1) pyautogui.click() pyautogui.hotkey('winleft', 'right') # ------------------------------------------------------------- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # Next command -- Tile window to the left. # ------------------------------------------------------------- elif 'left' in command: pyautogui.moveTo(2200, 1000, duration=.1) pyautogui.click() pyautogui.hotkey('winleft', 'left') # ------------------------------------------------------------- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # Next command -- Maximize window. # This is used a lot so that pyautogui can find controls. # ------------------------------------------------------------- elif 'maximize' in command: pyautogui.click() pyautogui.hotkey('winleft', 'up') # ------------------------------------------------------------- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # Next command -- Minimize window (hide.) # ------------------------------------------------------------- elif 'minimize' in command: pyautogui.click() pyautogui.hotkey('winleft', 'h') # ------------------------------------------------------------- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # End Interface With Desktop # Help Section # ------------------------------------------------------------- elif 'help' in command: talktome.talkToMe("The wake word is Julia") talktome.talkToMe("You can also use Juliet, Julius, or Julie") talktome.talkToMe("Julie Julie works best, however") talktome.talkToMe("You can always say Julie Julie HELP.") talktome.talkToMe("Julia also runs the listed commands that follow") talktome.talkToMe("Also, you can always say Julie Julie list commands.") talktome.talkToMe("You can ask Julia to") with open("commandlist") as file: for line in file: talktome.talkToMe(line) # ------------------------------------------------------------- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # Next command -- List commands uses the commandlist file # If you add commands to juliebrain.py, # also ad the command name to commandlist. # ------------------------------------------------------------- elif 'commands' in command: talktome.talkToMe("You can ask Julia to") with open("commandlist") as file: for line in file: # line = line.strip() talktome.talkToMe(line) # ------------------------------------------------------------- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # End Help Section # Miscelaneous -- Because it's short and runs fast, # this is a great command to test the system. # ------------------------------------------------------------- elif 'what\'s up' in command: talktome.talkToMe('Just doing my thing')
# クリック操作 x = 100 y = 100 time = 1 pyautogui.moveTo(x, y, time) # マウスカーソルを (x,y)の座標までtime秒で移動する.もしtime=0であればすぐに移動する. xOffset = 100 yOffset = 200 pyautogui.moveRel(xOffset, yOffset, time) #現在のマウスカーソルの座標から(xOffset,yOffset)だけtime秒で移動する. print('-' * 50) pyautogui.click(50, 100, 2, 0.5, 'left') print('-' * 50) pyautogui.rightClick(x,y) #右クリック pyautogui.middleClick(x,y) #真ん中クリック pyautogui.doubleClick(x,y) #ダブルクリック pyautogui.tripleClick(x,y) #トリプルクリック print('-' * 50) pyautogui.dragTo(x, y, time) #現在のマウスカーソルの座標から(x,y)の座標までtime秒でドラッグする. pyautogui.dragRel(xOffset, yOffset, time) # 現在のマウスカーソルの座標から(xOffset,yOffset)だけtime秒でドラッグし移動する pyautogui.mouseDown(x, y, button='left') pyautogui.mouseUp(x, y, button='left') amount_to_scroll = 1 #pyautogui.scroll(amount_to_scroll, x, y) interval = 1 pyautogui.typewrite('Hello world!\n', interval) # intervalは文字間の入力待機時間です.