def onClickRecordStart(self): command = "pgrep -l %s | awk '{print $1}'" %(self.current_game) child = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True) result = child.communicate()[0].strip() game_started = False options = kCGWindowListOptionOnScreenOnly geometry = None while game_started == False: window_list = CGWindowListCopyWindowInfo(options, kCGNullWindowID) for window in window_list: pid = window['kCGWindowOwnerPID'] if str(result) == str(pid): geometry = window['kCGWindowBounds'] print geometry game_started = True applescript = os.getcwd()+'/AppleScripts/recorder.scpt' command = 'osascript '+applescript os.system(command) mouse =Controller() time.sleep(1) mouse.position = (geometry['X'], geometry['Y']+(geometry['Height']-self.height)) time.sleep(1) print 'start : ('+str(geometry['X'])+', '+str(geometry['Y']+(geometry['Height']-self.height))+')' mouse.press(Button.left) time.sleep(1) mouse.position = (geometry['X']+geometry['Width'], geometry['Y']+geometry['Height']) print 'start : ('+str(geometry['X']+geometry['Width'])+', '+str( geometry['Y']+geometry['Height'])+')' time.sleep(1) mouse.release(Button.left) time.sleep(1) mouse.position = ((2*geometry['X']+geometry['Width'])/2, (2*geometry['Y']+2*geometry['Height']-self.height)/2) time.sleep(1) mouse.click(Button.left, 1)
def main(): path = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s" # Set path to location of Chrome.exe r = sr.Recognizer() # Define speech recognizer function m = sr.Microphone() # Define Microphone function mouse = Controller( ) # Define mouse as controller function from pynput library with m as source: # Set microphone as a source for speech recognition r.adjust_for_ambient_noise( source) # Adjustment for ambient noise to improve word recognition print("Request a song ") # Prompt user to request a song audio = r.listen(source) # Listen for a word and store into audio dest = r.recognize_google( audio) # Translate audio into text using google speech api if dest != 0: # Check for dest to be filled with text print("Searching now for: " + dest) # Print search with title from speech input time.sleep(3) # Sleep 3 seconds (To display audio search result) try: web.open( "https://open.spotify.com/search/" + dest ) # Open spotify and search for song results matching speech input time.sleep(20) # Sleep for 20 seconds to allow search mouse.position = (454, 285) # Position mouse to Top Result box mouse.click(Button.left, 2) # Click Top Result box, song will begin playing except Exception as e: # Exception for try: print("Error : " + str(e))
def moveIt(): global count count = count + 1 # Get time now = datetime.now() current_time = now.strftime("%H:%M:%S") currentPos = mouse.position # save current position of mouse! mouse.position = ( 2, 700) # move it to the left of the screen somewhere in the middle! time.sleep(0.1) # Wait a bit... mouse.move(5, 5) time.sleep(0.1) # Wait again... mouse.click(button.right, 1) # make a right click! time.sleep(0.1) # Wait... mouse.position = (int(currentPos[0]), int(currentPos[1]) ) #move mouse back to where it was! print("Count:", count, "Mouse moved at:", current_time) # # Keyboard action # time.sleep(0.1) # with keyboard.pressed(key.cmd): # keyboard.press(key.tab) # wait before click again... time.sleep(120)
def follow(): try: try: followbutton = driver.find_element_by_xpath('/html/body/div[4]/div[2]/div/article/header/div[2]/div[1]/div[2]/button') followbutton.click() if len(driver.find_elements_by_xpath('/html/body/div[5]/div/div')) > 0: cancel = driver.find_element_by_xpath('/html/body/div[5]/div/div/div[3]/button[2]') cancel.click() except NoSuchElementException: sleep(2) followbutton = driver.find_element_by_xpath('/html/body/div[4]/div[2]/div/article/header/div[2]/div[1]/div[2]/button') followbutton.click() if len(driver.find_elements_by_xpath('/html/body/div[5]/div/div')) > 0: cancel = driver.find_element_by_xpath('/html/body/div[5]/div/div/div[3]/button[2]') cancel.click() except ElementClickInterceptedException: mouse.position(1000,1000) mouse.click() followbutton = driver.find_element_by_xpath('/html/body/div[4]/div[2]/div/article/header/div[2]/div[1]/div[2]/button') followbutton.click() if len(driver.find_elements_by_xpath('/html/body/div[5]/div/div')) > 0: cancel = driver.find_element_by_xpath('/html/body/div[5]/div/div/div[3]/button[2]') cancel.click() except NoSuchElementException: next_post() next_post()
def draw(image_array: np.array) -> None: print(image_array) with Listener(on_press=on_press) as listener: listener.join() x, y = mouse.position for r, row in enumerate(image_array): for c, col in enumerate(row): if col: mouse.position = (x + c, y + r) mouse.click(Button.left, 1) sleep(0.0001)
def processing(operator): global FlowerpotCoords global ButtonCoords mouse = Controller() for fc, bc in zip(FlowerpotCoords, ButtonCoords): var.set(operator + 'ing......') mouse.position = fc mouse.click(Button.right, 1) time.sleep(0.5) mouse.position = bc mouse.click(Button.left, 1) time.sleep(0.5)
def execute(): #print("hello") # 复制 _control_C() #粘贴 mystr = pyperclip.paste() print('English:', mystr) # 翻译 chinese_str = translateToChinese(mystr) sendMessageToWindow(chinese_str) #点击一下防止直接念英文 mouse.click(pynput.mouse.Button.left) #朗读 _f1() print('===' * 30, '\n')
def infiniteClickr(self): vars = self._getVars() # small buffer in order to let user get to desired window sleep(5) mouse = Controller() # continue clicker indefinitely until interrupted through pause button or exit while True: if self.pause == True: break # evaluate which button user has selected to be clicked if vars[1] == "left": mouse.click(Button.left, vars[2]) sleep(vars[0]) else: mouse.click(Button.right, vars[2]) sleep(vars[0])
def finiteClickr(self): # vars = (0: total time || 1: left/right button || 2: single/double click || 3: times to repeat) vars = self._getVars() iter = vars[3] # small buffer in order to let user get to desired window sleep(5) mouse = Controller() # continue clicker until iteration has finished or pause button (makes pause True) is pressed while iter: if self.pause == True: break # check which button the user has selected to be clicked if vars[1] == "left": mouse.click(Button.left, vars[2]) sleep(vars[0]) iter -= 1 else: mouse.click(Button.right, vars[2]) sleep(vars[0]) iter -= 1
def click(self, width, height): self.move(width, height) mouse.click(button.left, 1)
start = {"mainscreen":(327,256),"leftscreen":(-906,209)} jump = {"mainscreen":(-787,380),"leftscreen":(-787,380)} Esc = {"mainscreen":(2109,194),"leftscreen":(-202,194)} exit = {"mainscreen":(320,1249),"leftscreen":(-891,591)} yes = {"mainscreen":(1475,981),"leftscreen":(-500,506)} Home = {"mainscreen":(1475,981),"leftscreen":(-20,700)} currentscreen = "leftscreen" mouse = Controller() for i in range(60): print(i+1) mouse.position = start[currentscreen] mouse.click(Button.left, 1) print("start") time.sleep(95) mouse.position = jump[currentscreen] mouse.click(Button.left, 1) print("jump") time.sleep(2) mouse.position = Esc[currentscreen] mouse.click(Button.left, 1) print("Esc") time.sleep(3)
def run(self): while self.program_running: while self.running: mouse.click(self.button) time.sleep(self.delay)
if joystickXY[0] <= 128: mouse.move(5, 0) if joystickXY[1] <= 128: mouse.move(0, 5) if joystickXY[0] > 128 and joystickXY[0] <= 384: mouse.move(10, 0) if joystickXY[1] > 128 and joystickXY[1] <= 384: mouse.move(0, 10) if joystickXY[0] > 384: mouse.move(20, 0) if joystickXY[1] > 384: mouse.move(0, 20) if GPIO.input(attack) == GPIO.HIGH: # Attack button pressed mouse.click(mouse.Button.left) if GPIO.input(right_click) == GPIO.HIGH: # Interact button pressed mouse.click(mouse.Button.right) if GPIO.input( move_right) == GPIO.HIGH: # If move right button is pressed keyboard.press('d') keyboard.release('d') if GPIO.input( move_left) == GPIO.HIGH: # if move left button is pressed keyboard.press('a') keyboard.release('a') if GPIO.input(
scaleFactor=1.05, minNeighbors=75) # if find_fist is not None: # mouse.click(pynput.mouse.Button.left,1) # time.sleep(1) if find_fist_init is None: find_fist_init = find_fist if find_fist == (): find_hand = cascade_hand.detectMultiScale(frame_gray, scaleFactor=1.05, minNeighbors=10) if find_hand != (): mouse.click(pynput.mouse.Button.left, 1) if find_fist != () and find_fist_init != (): delx, dely, delw, delh = find_fist[0][0] - find_fist_init[0][ 0], find_fist[0][1] - find_fist_init[0][1], find_fist[0][ 2] - find_fist_init[0][2], find_fist[0][3] - find_fist_init[0][ 3] mid_x = (delx + delx + delw) / 2 mid_y = (dely + dely + delh) / 2 mouse.move(-1 * 5 * delx, 5 * dely) # print (find_hand[0][0]) find_fist_init = find_fist #To show the rectangle on the frame make_rect_contours(find_fist, frame, 255, 0, 0)
def shotBall(newPos): mouse.position = BROWSERFIELDS[newPos[0]] mouse.click(Button.left, 2)
def playTutorial(): actionSequence = [15, 13, 11, 'SWITCH', 13, 1] for step in actionSequence: mouse.position = BROWSERFIELDS[step] mouse.click(Button.left, 2) time.sleep(1)
from pynput import mouse mouse = Controller() # Read pointer position print('The current pointer position is {0}'.format(mouse.position)) # Set pointer position mouse.position = (10, 20) print('Now we have moved it to {0}'.format(mouse.position)) # Move pointer relative to current position mouse.move(5, -5) # Press and release mouse.press(Button.left) mouse.release(Button.left) # Double click; this is different from pressing and releasing # twice on macOS mouse.click(Button.left, 2) # Scroll two steps down mouse.scroll(0, 2)
def func1(): while True: if a: break mouse.click(Button.left) time.sleep(0.0007)