Python pyautogui.typewrite() Examples

The following are 11 code examples of pyautogui.typewrite(). 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: _keyboard.py    From robotframework-imagehorizonlibrary with MIT License 8 votes vote down vote up
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) 
Example #2
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 #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: _keyboard.py    From robotframework-imagehorizonlibrary with MIT License 6 votes vote down vote up
def type_with_keys_down(self, text, *keys):
        '''Press keyboard keys down, then write given text, then release the
        keyboard keys.

        See valid keyboard keys in `Press Combination`.

        Examples:

        | Type with keys down | write this in caps  | Key.Shift |
        '''
        valid_keys = self._validate_keys(keys)
        for key in valid_keys:
            ag.keyDown(key)
        ag.typewrite(text)
        for key in valid_keys:
            ag.keyUp(key) 
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: test_easygui_qt.py    From easygui_qt with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def run(self):
        """Start running the test after a brief pause to allow
           the window or dialog to show on the screen
        """
        time.sleep(1.5)
        pyautogui.typewrite(self.msg, self.interval) 
Example #7
Source File: gmail_generator.py    From gmail-generator with MIT License 5 votes vote down vote up
def generate_info():

    # Print message
    msg(1,'Generating credentials...')

    # First and last name
    _first_name_=randomize('-l',7)
    pyautogui.typewrite(_first_name_)
    pyautogui.typewrite('\t')
    _last_name_=randomize('-l',8)
    pyautogui.typewrite(_last_name_)
    pyautogui.typewrite('\t')
    msg(2,'\x1b[0;33;40mName:\x1b[0m %s %s' % (_first_name_,_last_name_))

    # Username
    _username_=randomize('-l',10)
    pyautogui.typewrite(_username_)
    pyautogui.typewrite('\t')
    msg(2,'\x1b[0;33;40mUsername:\x1b[0m %s' % _username_)

    # Password
    _password_=randomize('-p',16)
    pyautogui.typewrite(_password_+'\t'+_password_+'\t')
    msg(2,'\x1b[0;33;40mPassword:\x1b[0m %s' % _password_)

    # Date of birth
    _month_=randomize('-m',1)
    _day_=randomize('-d',1)
    _year_=randomize('-y',1)
    pyautogui.typewrite(_month_+'\t'+str(_day_)+'\t'+str(_year_)+'\t')
    msg(2,'\x1b[0;33;40mDate of birth:\x1b[0m %s/%d/%d' % (_month_,_day_,_year_))

    # Gender (set to 'Rather not say')
    pyautogui.typewrite('R\t')
    msg(2,'\x1b[0;33;40mGender:\x1b[0m Rather not say')

    # Skip the rest
    pyautogui.typewrite('\t\t\t\t\n')

# Main function 
Example #8
Source File: test_pyautogui.py    From pyautogui with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def run(self):
        time.sleep(0.25)  # NOTE: BE SURE TO ACCOUNT FOR THIS QUARTER SECOND FOR TIMING TESTS!
        pyautogui.typewrite(self.msg, self.interval) 
Example #9
Source File: slack_messenger.py    From automate-the-boring-stuff-projects with MIT License 5 votes vote down vote up
def send_message(contact, message):
    """Sends message to an active slack contact
    Args:
        contact (str): contacts name on slack
        message (str): message to send to friend
    Returns:
        None
    """
    try:
        print('5 seconds to navigate to slack app..')
        time.sleep(5)

        # Use JumpTo slack feature
        pyautogui.hotkey('command', 'k')
        time.sleep(1)
        # Enter contact name in search box, click enter
        pyautogui.typewrite(contact)
        time.sleep(1)
        pyautogui.typewrite(['enter'])
        time.sleep(1)

        active = pyautogui.locateOnScreen('active_identifier.png')
        
        if not active:
            print(f'{contact} is not active, skipped contact')
            return
        
        print('Contact is active, sending message...')
        pyautogui.typewrite(['tab'])      
        pyautogui.typewrite(message)
        pyautogui.typewrite(['enter'])

    except KeyboardInterrupt:
        print('Process was cancelled..') 
Example #10
Source File: keyboard.py    From iris with Mozilla Public License 2.0 4 votes vote down vote up
def type(text: Key or str = None, modifier=None, interval: int = None):
        """Keyboard type.

        :param text: String or Key pressed
        :param modifier: Key modifier.
        :param interval: The number of seconds in between each press. By default it is 0 seconds.
        :return: None.
        """
        if modifier is None:
            if isinstance(text, Key):
                logger.debug("Type Method: [Reserved key: {}]".format(text))
                key_down(text)
                key_up(text)
                time.sleep(Settings.key_shortcut_delay)
            else:
                if interval is None:
                    interval = Settings.type_delay

                logger.debug("Type Method: [Text: {}]".format(text))
                pyautogui.typewrite(text, interval)
        else:
            from moziris.api.keyboard.keyboard_util import get_active_modifiers

            modifier_keys = get_active_modifiers(modifier)
            num_keys = len(modifier_keys)
            logger.debug(
                "Type Method: [Modifiers ({}): {}] + [Text: {}]".format(
                    num_keys, " ".join(key.name for key in modifier_keys), text
                )
            )
            if num_keys == 1:
                key_down(modifier_keys[0])
                time.sleep(Settings.key_shortcut_delay)
                key_down(text)
                time.sleep(Settings.key_shortcut_delay)
                key_up(text)
                time.sleep(Settings.key_shortcut_delay)
                key_up(modifier_keys[0])
            elif num_keys == 2:
                key_down(modifier_keys[0])
                time.sleep(Settings.key_shortcut_delay)
                key_down(modifier_keys[1])
                time.sleep(Settings.key_shortcut_delay)
                key_down(text)
                time.sleep(Settings.key_shortcut_delay)
                key_up(text)
                time.sleep(Settings.key_shortcut_delay)
                key_up(modifier_keys[1])
                time.sleep(Settings.key_shortcut_delay)
                key_up(modifier_keys[0])
            else:
                logger.error("Returned key modifiers out of range.")

        if Settings.type_delay != Settings.DEFAULT_TYPE_DELAY:
            Settings.type_delay = Settings.DEFAULT_TYPE_DELAY 
Example #11
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