当前位置: 首页>>代码示例>>Python>>正文


Python pyautogui.press方法代码示例

本文整理汇总了Python中pyautogui.press方法的典型用法代码示例。如果您正苦于以下问题:Python pyautogui.press方法的具体用法?Python pyautogui.press怎么用?Python pyautogui.press使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyautogui的用法示例。


在下文中一共展示了pyautogui.press方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: type

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import press [as 别名]
def type(self, *keys_or_text):
        '''Type text and keyboard keys.

        See valid keyboard keys in `Press Combination`.

        Examples:

        | Type | separated              | Key.ENTER | by linebreak |
        | Type | Submit this with enter | Key.enter |              |
        | Type | key.windows            | notepad   | Key.enter    |
        '''
        for key_or_text in keys_or_text:
            key = self._convert_to_valid_special_key(key_or_text)
            if key:
                ag.press(key)
            else:
                ag.typewrite(key_or_text) 
开发者ID:eficode,项目名称:robotframework-imagehorizonlibrary,代码行数:19,代码来源:_keyboard.py

示例2: basic_recovery

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import press [as 别名]
def basic_recovery():
        """Method that contains steps for basic recovery attempt, which
        involves clearing any interaction-blocking browser popups.

        Returns:
            bool: True if recovery was successful; False otherwise.
        """
        Log.log_debug("Attempting Basic Recovery.")

        if cfg.config.general.is_direct_control:
            pyautogui.moveTo(1, 1)
            pyautogui.press('esc')
            sleep(0.5)
            pyautogui.press('space')
            sleep(0.5)
            pyautogui.press('f10')
            sleep(0.5)

        try:
            if kca_u.kca.find_kancolle():
                return True
        except FindFailed:
            pass

        return False 
开发者ID:mrmin123,项目名称:kcauto,代码行数:27,代码来源:recovery.py

示例3: _refresh_screen

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import press [as 别名]
def _refresh_screen(screen):
        """Helper method that contains steps for refreshing the tab. Includes
        logic to re-instantiate neccessary Chrome hooks.

        Args:
            screen (Region, optional): screen region.
        """
        if cfg.config.general.is_direct_control:
            pyautogui.press('f5')
            sleep(0.5)
            pyautogui.press('space')
            sleep(0.5)
            pyautogui.press('tab')
            sleep(0.5)
            pyautogui.press('space')
            sleep(5)
        else:
            kca_u.kca.visual_hook.Page.reload()
            sleep(0.5)

        kca_u.kca.wait(screen, 'global|game_start.png', 90)
        sleep(3) 
开发者ID:mrmin123,项目名称:kcauto,代码行数:24,代码来源:recovery.py

示例4: _Input

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import press [as 别名]
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)) 
开发者ID:Sandmann79,项目名称:xbmc,代码行数:26,代码来源:playback.py

示例5: play_game

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import press [as 别名]
def play_game(self, get_command_callback: Callable[[int, int, int], str]) -> int:
        self.start_game()

        start = last_compute_speed = last_command_time = time.time()
        last_distance = self.landscape['width']
        speed = 0
        last_speeds = [3] * 30

        while True:
            buffer = self.shooter.grab(self.landscape)
            image = Image.frombytes('RGB', buffer.size, buffer.rgb).convert('L')
            image = np.array(image)
            image += np.abs(247 - image[0, self.x2])
            roi = image[self.y1:self.y2, self.x1:self.x2]
            score = int((time.time() - start) * 10)
            distance, size = self.compute_distance_and_size(roi, self.x2)
            speed = self.compute_speed(distance, last_distance, speed, last_speeds, last_compute_speed)
            last_compute_speed = time.time()
            # Check GAME OVER
            if distance == last_distance or distance == 0:
                res = cv2.matchTemplate(image, self.gameover_template, cv2.TM_CCOEFF_NORMED)
                if np.max(res) > 0.5:
                    return score
            last_distance = distance
            if time.time() - last_command_time < 0.6:
                continue
            command = get_command_callback(distance, size, speed)
            if command:
                last_command_time = time.time()
                pyautogui.press(command) 
开发者ID:pauloalves86,项目名称:go_dino,代码行数:32,代码来源:dino_api.py

示例6: start_game

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import press [as 别名]
def start_game():
        pyautogui.press('up')
        time.sleep(.3)
        pyautogui.press('up')
        time.sleep(.3)
        pyautogui.press('up')
        time.sleep(1.) 
开发者ID:pauloalves86,项目名称:go_dino,代码行数:9,代码来源:dino_api.py

示例7: locate_gmail

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import press [as 别名]
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 
开发者ID:unix121,项目名称:gmail-generator,代码行数:39,代码来源:gmail_generator.py

示例8: run

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import press [as 别名]
def run(self):
        time.sleep(0.25)  # NOTE: BE SURE TO ACCOUNT FOR THIS QUARTER SECOND FOR TIMING TESTS!
        pyautogui.press(self.keysArg) 
开发者ID:asweigart,项目名称:pyautogui,代码行数:5,代码来源:test_pyautogui.py

示例9: test_failsafe

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import press [as 别名]
def test_failsafe(self):
        self.oldFailsafeSetting = pyautogui.FAILSAFE

        pyautogui.moveTo(1, 1)  # make sure mouse is not in failsafe position to begin with
        for x, y in pyautogui.FAILSAFE_POINTS:
            pyautogui.FAILSAFE = True
            # When move(), moveTo(), drag(), or dragTo() moves the mouse to a
            # failsafe point, it shouldn't raise the fail safe. (This would
            # be annoying. Only a human moving the mouse to a failsafe point
            # should trigger the failsafe.)
            pyautogui.moveTo(x, y)

            pyautogui.FAILSAFE = False
            pyautogui.moveTo(1, 1)  # make sure mouse is not in failsafe position to begin with (for the next iteration)

        pyautogui.moveTo(1, 1)  # make sure mouse is not in failsafe position to begin with
        for x, y in pyautogui.FAILSAFE_POINTS:
            pyautogui.FAILSAFE = True
            pyautogui.moveTo(x, y)  # This line should not cause the fail safe exception to be raised.

            # A second pyautogui function call to do something while the cursor is in a fail safe point SHOULD raise the failsafe:
            self.assertRaises(pyautogui.FailSafeException, pyautogui.press, "esc")

            pyautogui.FAILSAFE = False
            pyautogui.moveTo(1, 1)  # make sure mouse is not in failsafe position to begin with (for the next iteration)

        for x, y in pyautogui.FAILSAFE_POINTS:
            pyautogui.FAILSAFE = False
            pyautogui.moveTo(x, y)  # This line should not cause the fail safe exception to be raised.

            # This line shouldn't cause a failsafe to trigger because FAILSAFE is set to False.
            pyautogui.press("esc")

        pyautogui.FAILSAFE = self.oldFailsafeSetting 
开发者ID:asweigart,项目名称:pyautogui,代码行数:36,代码来源:test_pyautogui.py

示例10: auto_message

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import press [as 别名]
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 
开发者ID:IFinners,项目名称:automate-the-boring-stuff-projects,代码行数:42,代码来源:im_bot.py

示例11: press_key

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import press [as 别名]
def press_key(key, interval=None):
	if interval is not None:
		time.sleep(interval)
	keys = parser.parse_key(key)
	count = len(keys)
	if count == 1:
		pyautogui.press(keys[0])
	elif count == 2:
		pyautogui.hotkey(keys[0], keys[1])

# Type text 
开发者ID:AXeL-dev,项目名称:Dindo-Bot,代码行数:13,代码来源:tools.py

示例12: type_text

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import press [as 别名]
def type_text(text, interval=0.1):
	for c in text:
		if c.isdigit():
			pyautogui.hotkey('shift', c, interval=0.1)
		else:
			pyautogui.press(c)
		time.sleep(interval)

# Scroll to value 
开发者ID:AXeL-dev,项目名称:Dindo-Bot,代码行数:11,代码来源:tools.py

示例13: jump

# 需要导入模块: import pyautogui [as 别名]
# 或者: from pyautogui import press [as 别名]
def jump():
    global X
    pyautogui.press("up")
    X += 0.4  # Increment in detection region for increase speed of game 
开发者ID:guilhermej,项目名称:dino_chrome_bot,代码行数:6,代码来源:dino_chrome_bot.py


注:本文中的pyautogui.press方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。