我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用pyautogui.keyDown()。
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 applyChain(file): p = subprocess.Popen(["audacity", "./{}".format(file)]) time.sleep(7) try: pyautogui.click(pyautogui.locateCenterOnScreen('src/images/discard.png')) time.sleep(1) pyautogui.click(pyautogui.locateCenterOnScreen('src/images/yes.png')) except: pass time.sleep(1) if len(list(pyautogui.locateAllOnScreen('src/images/audacity_fileButton.png'))) > 1: pyautogui.keyDown('alt') pyautogui.press('f10') pyautogui.keyUp('alt') time.sleep(1) pyautogui.click(pyautogui.locateCenterOnScreen('src/images/audacity_fileButton.png')) time.sleep(2) pyautogui.click(pyautogui.locateCenterOnScreen('src/images/audacity_applyChain.png')) time.sleep(2) pyautogui.click(pyautogui.locateCenterOnScreen('src/images/audacity_applyToCurrentFile.png')) time.sleep(10) p.terminate() print('Done')
def handle_select_combination_intent(self, message): self.speak("Selecting all") pyautogui.hotkey("ctrl", "a") if message.data.get("PasteKeyword"): self.handle_paste_intent(message) elif message.data.get("CopyKeyword"): self.handle_copy_intent(message) elif message.data.get("CutKeyword"): self.handle_cut_intent(message) elif message.data.get("DeleteKeyword"): self.speak("deleting") pyautogui.keyDown("delete") pyautogui.keyUp("delete")
def maxWindow(): try: pyautogui.click(pyautogui.locateCenterOnScreen('src/images/discard.png')) time.sleep(1) pyautogui.click(pyautogui.locateCenterOnScreen('src/images/yes.png')) except: pass time.sleep(1) if len(list(pyautogui.locateAllOnScreen('src/images/audacity_fileButton.png'))) > 1: pyautogui.keyDown('alt') pyautogui.press('f10') pyautogui.keyUp('alt')
def press(): pyautogui.keyDown('space')
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 handle_press_key_intent(self, message): key = message.data.get('Key') self.speak("Pressing %s" % key) pyautogui.keyDown(key) pyautogui.keyUp(key)
def handle_hold_key_intent(self, message): key = message.data.get('Key') self.speak("Holding down %s key" % key) pyautogui.keyDown(key)
def type_this(strings): """Types the passed characters with random pauses in between strokes""" for s in strings: # delay between key presses--key UP/DOWN #autopy.key.toggle(s, True) pyautogui.keyDown(s) RandTime.randTime(0,0,0,0,0,9) pyautogui.keyUp(s) # delay after key UP--next key