我们从Python开源项目中,提取了以下17个代码示例,用于说明如何使用pyautogui.typewrite()。
def basic_api(): x, y = pg.size() print x, y ''' pg.moveTo(300,300,2) pg.moveTo(300,400,2) pg.moveTo(500,400,2) pg.moveTo(500,300,2) pg.moveTo(300,300,2) #pg.moveTo(300,500,2) ''' # pg.click(100,100) word = [u'??', u'???'] pos = [452, 321] pg.moveTo(pos[0], pos[1]) pg.click() pg.typewrite(word[0])
def example(): screenWidth, screenHeight = pg.size() currentMouseX, currentMouseY = pg.position() pg.moveTo(500, 550) pg.click() pg.moveRel(None, 10) # move mouse 10 pixels down pg.doubleClick() # pg.moveTo(500, 500, duration=2, tween=pyautogui.tweens.easeInOutQuad) # use tweening/easing function to move mouse over 2 seconds. pg.typewrite('Hello world!', interval=0.25) # type with quarter-second pause in between each key pg.press('esc') pg.keyDown('shift') pg.press(['left', 'left', 'left', 'left', 'left', 'left']) pg.keyUp('shift') pg.hotkey('ctrl', 'c') delta_y = 50
def random_typer(word): for i in word: pyautogui.typewrite(i, interval=random.random()/4)
def main(): box_1_coords = (43, 442, 159, 42) box_2_coords = (215, 442, 159, 42) box_3_coords = (387, 442, 159, 42) box_4_coords = (43, 498, 159, 42) box_5_coords = (215, 498, 159, 42) box_6_coords = (387, 498, 159, 42) time.sleep(3) list_of_items = ['Incandescent energy', 'Coal', 'Fire rune', 'Air rune', 'Feather', 'Broad arrowheads', 'Maple logs', 'Water rune', 'Earth rune', 'Nature rune', 'Yew logs', 'Brilliant energy', 'Blood rune', 'Mind rune', 'Cannonball', 'Lustrous energy', 'Luminous energy', 'Dragon bones', 'Body rune', 'Mahogany plank', 'Death rune', 'Royal bolts', 'Ascension bolts', 'Fishing bait', 'Rune arrow', 'Chaos rune', 'Bowstring', 'Ascension shard', 'Radiant energy', 'Ganodermic flake', 'Adamantite ore', 'Gold ore', 'Flax', 'Vial of water', 'Vibrant energy', 'Araxyte arrow', 'Mahogany logs', 'Raw shark', 'Shark', 'Soul rune', 'Rocktail', 'Adamant bar', 'Rune bar', 'Gold bar', 'Elder energy', 'Runite ore', 'Law rune', 'Raw lobster', 'Raw rocktail', 'Astral rune', 'Cosmic rune', 'Black dragon leather', 'Onyx bolts (e)', 'Steel bar', 'Magic shieldbow', 'Iron ore', 'Black dragonhide', 'Grenwall spikes', 'Mithril bar', 'Willow logs', 'Mud rune', 'Lobster', 'Swamp tar', 'Mithril ore', 'Adamant arrow', 'Snape grass', 'Soft clay', 'Magic notepaper', 'Steel arrow', 'Magic shieldbow (u)', 'Harralander tar', 'Mithril arrow', 'Teak plank', 'Thread', 'Oak plank', 'Dark arrow', 'Grimy dwarf weed', 'Dragon arrowheads', 'Grimy lantadyme', 'Airut bones', 'Gleaming energy', 'Infernal ashes', 'Frost dragon bones', 'Living minerals', 'Chitin scraps', 'Green dragon leather', 'Red chinchompa', 'Rune arrowheads', 'Clean lantadyme', 'Rune essence', 'Raw tuna', 'Hydrix bolt tips', 'Yew seed', 'Palm tree seed', 'Teleport to house', 'Wine of Zamorak', 'Potion flask', 'Prayer potion (4)', 'Super restore (4)', 'Saradomin brew (4)', 'Aggression potion (4)', 'Prayer renewal (4)'] list_of_file_names = [] for i in range(len(list_of_items)): list_of_file_names.append(list_of_items[i].replace(' ', '_')+'.png') for i in range(len(list_of_items)): file_name_1 = 'screenshots/items/nxt_items/'+list_of_file_names[i] file_name_2 = 'screenshots/temp_items/'+list_of_file_names[i] if os.path.isfile(file_name_1): print('file exists', file_name_1) continue x = len(list_of_items[i]) pyautogui.typewrite(list_of_items[i], random.random()/10) time.sleep(4) pyautogui.screenshot(file_name_2, region=(box_2_coords)) for x in range(x): pyautogui.press('backspace') time.sleep(random.random()/10) time.sleep(1)
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(1) # 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
def locate_gmail(): #Sleep for a while and wait for Firefox to open time.sleep(2) # 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<mpl=default') pyautogui.typewrite('\n') # Wait for a while until the website responds time.sleep(3) # Print a simple message msg(1,'Locating the form...') # Locate the form _gmail_=pyautogui.locateOnScreen('images/gmail_form.png') _form_=pyautogui.center(_gmail_) # Check and print message if not pyautogui.click(_form_): msg(1,'Located the form.') else: msg(3,'Failed to locate the form.') ext() # Function used to randomize credentials
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
def behaviour3() : strlen = random.randInt (1, 1000) randomstring = ''.join (random.choice (string.lowercase) for i in range (strlen)) pyautogui.typewrite (randomstring) for x in range (1, 7) : pyautogui.hotkey ('ctrl', 'v')
def on_click(x, y, button, pressed): global msg global lasttime if pressed: if Button.left == button: msg += "." lasttime = time.time() if Button.right == button: msg += "-" lasttime = time.time() else: # print(msg) newtime = time.time() #print (newtime - lasttime) if (newtime - lasttime) > 0.5: print(msg) if msg in esrom: pyautogui.typewrite(esrom[msg]) if esrom[msg]=="w": pyautogui.moveRel(0, -50, duration=0.5) if esrom[msg]=="a": pyautogui.moveRel(-50, 0, duration=0.5) if esrom[msg]=="s": pyautogui.moveRel(0, 50, duration=0.5) if esrom[msg]=="d": pyautogui.moveRel(50, 0, duration=0.5) msg = "" return True # Collect events forever
def launch_game(cls): logger.info("Launching Game") cls.delay(cls.click_pic, 'playdota.png') cls.delay(cls.click_pic, 'createlobby.png') cls.delay(cls.click_pic, 'startgame.png') cls.delay(pa.click, 282, 748, delay_secs=10) cls.delay(PressKey, 0x1C, delay_secs=8) cls.delay(ReleaseKey, 0x1C) cls.delay(pa.typewrite, "-startgame") cls.delay(PressKey, 0x1C) cls.delay(ReleaseKey, 0x1C)
def single_log_line(cls, log_string): cls.delay(PressKey, 0x27) ReleaseKey(0x27) cls.delay(pa.typewrite, log_string) cls.delay(cls.click_pic, 'submit.png') # Pressing enter doesnt seem to work here? cls.delay(PressKey, 0x27) ReleaseKey(0x27) pa.moveRel(25, 25) # Cannot recognise submit button if cursor still over it
def leave_game(cls): logger.info("Leaving Game") cls.delay(PressKey, 0x27) cls.delay(ReleaseKey, 0x27) cls.delay(pa.typewrite, "disconnect") cls.delay(PressKey, 0x1C) cls.delay(ReleaseKey, 0x1C) cls.delay(PressKey, 0x27) cls.delay(ReleaseKey, 0x27) cls.delay(cls.click_pic, 'leave.png', delay_secs=2) cls.delay(cls.click_pic, 'leave_confirm.png')
def click_and_type(cls, x, y, text): # pyautogui.moveTo(x, y, duration=0.1) pyautogui.click(x, y, clicks=2, interval=cls.short_wait/2.0, duration=cls.short_wait) sleep(cls.short_wait * 2.0) pyautogui.typewrite(text, interval=cls.short_wait)
def enter_key(cls): sleep(cls.short_wait) pyautogui.typewrite(['enter', ])
def tab_key(cls): sleep(cls.short_wait) pyautogui.typewrite(['tab', ])
def type(cls, text): sleep(cls.short_wait) pyautogui.typewrite(text, interval=cls.short_wait)
def handle_type_intent(self, message): self.speak_dialog("typing") text = message.data.get('Text') pyautogui.typewrite(text, interval=0.05)