Python pyautogui.click() Examples

The following are 27 code examples of pyautogui.click(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pyautogui , or try the search function .
Example #1
Source File: gmail_generator.py    From gmail-generator with MIT License 7 votes vote down vote up
def open_firefox():

    # Printing basic message
    msg(1,'Opening Firefox...')

    # Location the start button
    _start_button_=pyautogui.locateOnScreen('images/start_button.png')
    _location_=pyautogui.center(_start_button_)

    # Clicking the start button
    if not  pyautogui.click(_location_):
        msg(1,'Opened start menu successfully!')
    else:
        msg(3,'Failed to open start menu!')
        ext()

    time.sleep(2)

    # Search for Firefox in the menu search
    pyautogui.typewrite('firefox')
    pyautogui.typewrite('\n')
    
    # Print message
    msg(1,'Firefox is now open and running.')


# Function used to locate GMail 
Example #2
Source File: mac_interface.py    From robotstreamer with Apache License 2.0 7 votes vote down vote up
def handleCommand(command, keyPosition):
                global freePongActive
                if command == 'FIRE':
                    print("fire, clicking mouse")
                    # Line below change to what control you want to assign to the premium button.
                    pyautogui.click(button='right')
                if command == 'FREE_FIRE':
                    print("processing fire")
                    if not freePongActive:
                        freePongActive = True
                        print("free pong fire was enabled")
                        # Line below change to what control you want to assign to free button.
                        pyautogui.click(button='right')
                        print("free ping pong", freePongActive)
                        # Time delay you want in seconds between when they can free fire.
                        time.sleep(10)
                        freePongActive = False
                    else:
                        print("ping pong not enabled") 
Example #3
Source File: gmail_generator.py    From gmail-generator with MIT License 6 votes vote down vote up
def locate_gmail():
    
    #Sleep for a while and wait for Firefox to open
    time.sleep(3)

    # Printing message
    msg(1,'Opening Gmail...')

    # Typing the website on the browser
    pyautogui.keyDown('ctrlleft');  pyautogui.typewrite('a'); pyautogui.keyUp('ctrlleft')
    pyautogui.typewrite('https://accounts.google.com/SignUp?service=mail&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&ltmpl=default')
    pyautogui.typewrite('\n')
    
    # Wait for a while until the website responds
    time.sleep(6)

    # Print a simple message
    msg(1,'Locating the form...')

    # Locate the form
    pyautogui.press('tab')
 
    time.sleep(2)

    _gmail_ = pyautogui.locateOnScreen('images/gmail_form.png')
    formx, formy = pyautogui.center(_gmail_)
    pyautogui.click(formx, formy)
    
    # Check and print message
    if not pyautogui.click(formx, formy):
        msg(1,'Located the form.')
    else:
        msg(3,'Failed to locate the form.')
        ext()


# Function used to randomize credentials 
Example #4
Source File: tools.py    From Dindo-Bot with MIT License 6 votes vote down vote up
def adjust_click_position(click_x, click_y, window_width, window_height, dest_x, dest_y, dest_width, dest_height):
	# get screen size
	screen_width, screen_height = pyautogui.size()
	if screen_width > window_width and screen_height > window_height:
		# fit position to destination size
		new_x, new_y = fit_position_to_destination(click_x, click_y, window_width, window_height, dest_width, dest_height)
		#print('new_x: %d, new_y: %d, dest_x: %d, dest_y: %d' % (new_x, new_y, dest_x, dest_y))
		# scale to screen
		x = new_x + dest_x
		y = new_y + dest_y
	else:
		x = click_x
		y = click_y
	return (x, y)

# Perform a simple click or double click on x, y position 
Example #5
Source File: im_bot.py    From automate-the-boring-stuff-projects with MIT License 6 votes vote down vote up
def auto_message(name, message):
    """Searches for friend on Google Hangouts and messages them."""
    print("Make sure the Google Hangout 'Conversations' page is visible and "
          "your cursor is not currently on the page.")
    time.sleep(3)

    search_bar = pyautogui.locateOnScreen('search.png')
    pyautogui.click(search_bar)
    pyautogui.typewrite(name)
    time.sleep(1)

    online_select = pyautogui.locateOnScreen('online-friend.png')
    if online_select is None:
        print('Friend not found or currently offline.')
        return
    else:
        pyautogui.doubleClick(online_select)

    attempts = 3
    while attempts > 0:
        message_box = pyautogui.locateOnScreen('message.png')
        pyautogui.click(message_box)
        pyautogui.typewrite(message)

        # If it can no longer be found it is because the message was entered.
        if pyautogui.locateOnScreen('message.png') is None:
            pyautogui.press('enter')
            pyautogui.press('esc')
            print('Message sent to {}'.format(name))
            break
        else:
            if attempts == 1:
                print('Unable to send message to {}.'.format(name))
                pyautogui.press('esc')

            else:
                print('Sending message to {} failed. Another {} attempts will '
                      'be made before moving on.'.format(name, attempts))

            attempts -= 1 
Example #6
Source File: __init__.py    From robotframework-imagehorizonlibrary with MIT License 6 votes vote down vote up
def _click_to_the_direction_of(self, direction, location, offset,
                                   clicks, button, interval):
        x, y = self._get_location(direction, location, offset)
        try:
            clicks = int(clicks)
        except ValueError:
            raise MouseException('Invalid argument "%s" for `clicks`')
        if button not in ['left', 'middle', 'right']:
            raise MouseException('Invalid button "%s" for `button`')
        try:
            interval = float(interval)
        except ValueError:
            raise MouseException('Invalid argument "%s" for `interval`')

        LOGGER.info('Clicking %d time(s) at (%d, %d) with '
                    '%s mouse button at interval %f' % (clicks, x, y,
                                                        button, interval))
        ag.click(x, y, clicks=clicks, button=button, interval=interval) 
Example #7
Source File: windows_interface.py    From robotstreamer with Apache License 2.0 6 votes vote down vote up
def handleCommand(command, keyPosition):
                global freePongActive
                if command == 'FIRE':
                    print("fire, clicking mouse")
                    # Line below change to what control you want to assign to the premium button.
                    pyautogui.click(button='right')
                if command == 'FREE_FIRE':
                    print("processing fire")
                    if not freePongActive:
                        freePongActive = True
                        print("free pong fire was enabled")
                        # Line below change to what control you want to assign to free button.
                        pyautogui.click(button='right')
                        print("free ping pong", freePongActive)
                        # Time delay you want in seconds between when they can free fire.
                        time.sleep(10)
                        freePongActive = False
                    else:
                        print("ping pong not enabled") 
Example #8
Source File: lianliankan.py    From lianliankan with MIT License 5 votes vote down vote up
def execute_one_step(one_step):
    from_row, from_col, to_row, to_col = one_step

    from_x = game_area_left + (from_col + 0.5) * grid_width
    from_y = game_area_top + (from_row + 0.5) * grid_height

    to_x = game_area_left + (to_col + 0.5) * grid_width
    to_y = game_area_top + (to_row + 0.5) * grid_height

    pyautogui.moveTo(from_x, from_y)
    pyautogui.click()

    pyautogui.moveTo(to_x, to_y)
    pyautogui.click() 
Example #9
Source File: hearthstone_auto.py    From hearthstone_script- with MIT License 5 votes vote down vote up
def mouse_click(inx, iny):
    pymouse.click(inx, iny) 
Example #10
Source File: autoplay.py    From AIGames with MIT License 5 votes vote down vote up
def auto_play(bbox):
	api = API_Class()
	count = 0
	click_num = 100
	while True:
		img_rgb = api.screenshot(bbox=bbox)
		img_rgb = np.array(img_rgb)
		gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
		ret, gray_thresh = cv2.threshold(gray, 5, 255, cv2.THRESH_BINARY_INV)
		# 形态学处理-腐蚀
		gray_erode = cv2.erode(gray_thresh, None, iterations=5)
		# 轮廓检测
		img, contours, hierarchy = cv2.findContours(gray_erode.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
		for contour in contours:
			min_1 = tuple(contour[contour[:, :, 1].argmin()][0])
			min_2 = tuple(contour[contour[:, :, 0].argmin()][0])
			max_1 = tuple(contour[contour[:, :, 1].argmax()][0])
			max_2 = tuple(contour[contour[:, :, 0].argmax()][0])
			# 如果检测到的是小轮廓,应该不是需要点击的黑块
			if max_1[1] - min_1[1] < 50:
				continue
			x = (min_2[0] + max_2[0]) // 2
			y = max_1[1] - 15
			position = (x + bbox[0], y + bbox[1])
			api.click(position)
			count += 1
		if count > click_num:
			break 
Example #11
Source File: autoplay.py    From AIGames with MIT License 5 votes vote down vote up
def click(self, position):
		# pyautogui.moveTo(position[0], position[1], duration=1)
		pyautogui.click(position[0], position[1])
	# 截屏 
Example #12
Source File: humanclicker.py    From pyclick with MIT License 5 votes vote down vote up
def click(self):
        pyautogui.click() 
Example #13
Source File: YuHunModule.py    From yysScript with Apache License 2.0 5 votes vote down vote up
def Click(targetPosition):
    """
    点击屏幕上的某个点
    :param targetPosition:
    :return:
    """
    if targetPosition is None:
        print('未检测到目标')
    else:

        pyautogui.moveTo(targetPosition, duration=0.20)
        pyautogui.click()
        time.sleep(random.randint(500, 1000) / 1000)

        # time.sleep(random.randint(100, 150) / 1000) 
Example #14
Source File: tools.py    From Dindo-Bot with MIT License 5 votes vote down vote up
def perform_click(x, y, double=False):
	old_position = pyautogui.position()
	if double:
		pyautogui.doubleClick(x=x, y=y, interval=0.1)
	else:
		pyautogui.click(x=x, y=y)
	pyautogui.moveTo(old_position)

# Press key 
Example #15
Source File: tools.py    From Dindo-Bot with MIT License 5 votes vote down vote up
def fit_position_to_destination(x, y, window_width, window_height, dest_width, dest_height):
	# new coordinate = old coordinate / (window size / destination size)
	new_x = x / (window_width / float(dest_width))
	new_y = y / (window_height / float(dest_height))
	return (int(new_x), int(new_y))

# Adjust click position 
Example #16
Source File: _mouse.py    From robotframework-imagehorizonlibrary with MIT License 5 votes vote down vote up
def click(self, button='left'):
        '''Clicks with the specified mouse button.

        Valid buttons are ``left``, ``right`` or ``middle``.
        '''
        ag.click(button=button) 
Example #17
Source File: _recognize_images.py    From robotframework-imagehorizonlibrary with MIT License 5 votes vote down vote up
def click_image(self, reference_image):
        '''Finds the reference image on screen and clicks it once.

        ``reference_image`` is automatically normalized as described in the
        `Reference image names`.
        '''
        center_location = self.locate(reference_image)
        LOGGER.info('Clicking image "%s" in position %s' % (reference_image,
                                                            center_location))
        ag.click(center_location)
        return center_location 
Example #18
Source File: Clicker.py    From roc with MIT License 5 votes vote down vote up
def centerclick(cls, clicks=1, interval=1, button='left', yat=1):
        rect =cls.find_window_movetop()
        posx = rect[0]
        posy = rect[1]
        w = rect[2] - posx
        h = rect[3] - posy

        # print('Clicking on: (' + str(coords[0]) + ', ' + str(coords[1]) + ')')
        pyautogui.click(m.ceil(w/2+posx), m.ceil(h/2+posy), clicks, interval, button) 
Example #19
Source File: Clicker.py    From roc with MIT License 5 votes vote down vote up
def click(cls,coords, clicks=1, interval=1, button='left', yat=1):
        rect =cls.find_window_movetop()
        posx = rect[0]
        posy = rect[1]

        base = 0.3+random.random()*random.random()*0.9
        print(base)
        sleep(base)
        print(m.ceil(coords[0]+posx), m.ceil(coords[1]+posy))
        # print('Clicking on: (' + str(coords[0]) + ', ' + str(coords[1]) + ')')
        pyautogui.click(m.ceil(coords[0]+posx), m.ceil(coords[1]+posy), clicks, interval, button) 
Example #20
Source File: Clicker.py    From roc with MIT License 5 votes vote down vote up
def repeat_click(cls,say, adjust_x=0, adjust_y=0, interval=0.10):
        rect =cls.find_window_movetop()
        posx = rect[0]
        posy = rect[1]

        x, y = pyautogui.position()
        x = x+adjust_x
        y = y+adjust_y
        print(x, y)
        pyautogui.click(m.ceil(x+posx), m.ceil(y+posy), clicks=say-1, interval=interval) 
Example #21
Source File: imagesearch.py    From python-imagesearch with MIT License 5 votes vote down vote up
def click_image(image, pos, action, timestamp, offset=5):
    img = cv2.imread(image)
    height, width, channels = img.shape
    pyautogui.moveTo(pos[0] + r(width / 2, offset), pos[1] + r(height / 2, offset),
                     timestamp)
    pyautogui.click(button=action) 
Example #22
Source File: dino_api.py    From go_dino with GNU General Public License v3.0 5 votes vote down vote up
def get_game_landscape_and_set_focus_or_die(self, threshold=0.7) -> Dict:
        tries = 0
        landscape = None
        while not landscape:
            landscape = self.find_game_position(threshold)
            if landscape or tries == 10:
                break
            else:
                tries += 1
            time.sleep(1)
        if not landscape:
            print("Can't find the game!")
            exit(1)
        pyautogui.click(landscape['left'], landscape['top'] + landscape['height'])
        return landscape 
Example #23
Source File: AutoClick.py    From PyKinectTk with GNU General Public License v3.0 5 votes vote down vote up
def run(self):
        while self.running:
            self.click()
            sleep(self.time_step)
            if (self.x, self.y) != position():
                self.running=False 
Example #24
Source File: AutoClick.py    From PyKinectTk with GNU General Public License v3.0 5 votes vote down vote up
def fromPosition():
        raw_input("Hover over the location you want to click and press enter")
        return position() 
Example #25
Source File: AutoClick.py    From PyKinectTk with GNU General Public License v3.0 5 votes vote down vote up
def click(self):
        click(self.x, self.y) 
Example #26
Source File: playback.py    From xbmc with GNU General Public License v3.0 3 votes vote down vote up
def _Input(mousex=0, mousey=0, click=0, keys=None, delay='0.2'):
    import pyautogui
    '''Control the user's mouse and/or keyboard.
       Arguments:
         mousex, mousey - x, y co-ordinates from top left of screen
         keys - list of keys to press or single key
    '''
    g = Globals()
    screenWidth, screenHeight = pyautogui.size()
    mousex = int(screenWidth / 2) if mousex == -1 else mousex
    mousey = int(screenHeight / 2) if mousey == -1 else mousey
    exit_cmd = [('alt', 'f4'), ('ctrl', 'shift', 'q'), ('command', 'q')][(g.platform & -g.platform).bit_length() - 1]

    if keys:
        if '{EX}' in keys:
            pyautogui.hotkey(*exit_cmd)
        else:
            pyautogui.press(keys, interval=delay)
    else:
        pyautogui.moveTo(mousex, mousey)
        if click:
            pyautogui.click(clicks=click)

    Log('Input command: Mouse(x={}, y={}, click={}), Keyboard({})'.format(mousex, mousey, click, keys)) 
Example #27
Source File: dolphin.py    From phillip with GNU General Public License v3.0 0 votes vote down vote up
def __call__(self):
    args = [self.exe, "--user", self.user]
    if not self.netplay:
      args += ["--exec", self.iso]
    if self.movie is not None:
      args += ["--movie", self.movie]
    
    print(args)
    process = subprocess.Popen(args)
    
    if self.netplay:
      import time
      time.sleep(2) # let dolphin window spawn
      
      import pyautogui
      #import ipdb; ipdb.set_trace()
      pyautogui.click(150, 150)
      #pyautogui.click(50, 50)
      time.sleep(0.5)
      pyautogui.hotkey('alt', 't') # tools

      time.sleep(0.5)
      pyautogui.hotkey('n') # netplay
      
      time.sleep(1) # allow netplay window time to spawn
      
      #return process
      
      #pyautogui.hotkey('down') # traversal
      
      #for _ in range(3): # move to textbox
      #  pyautogui.hotkey('tab')
      
      #pyautogui.typewrite(self.netplay) # write traversal code
      
      #return process
      
      time.sleep(0.1)
      # connect
      #pyautogui.hotkey('tab')
      pyautogui.hotkey('enter')

      #import ipdb; ipdb.set_trace()
    
    return process