pyautogui learning module

In the daily implementation, we use the controls on most of the pages and the client can be picked up operation. But a small part of the application is still unable to operate. Here I used to pyautogui this module. Here be shared.

The Python pyautogui module for automatically moving the mouse and the keyboard input by the user. The module comes with Python is not, so the following command to install

# Pyautogui module dependent module image, no image will be reported ImportError: No module named 'PIL' error 

PIP install image 

PIP install pyautogui

Official document describes: https://pyautogui.readthedocs.io/en/latest/

pyautogui Import 

'' '1. size (): used to obtain the screen resolution' '' 
Print ( "computer current resolution:", pyautogui.size ()) 
Print (of the type (pyautogui.size ())) 

'' '2.moveTo (): for the movement of the mouse' '' 
pyautogui.moveTo (100,100, DURATION =. 1) 

'' '3.moveRel (): the current position, move the mouse pointer relative to' '' 
pyautogui.moveRel (0 , 300, DURATION =. 1) 

'' '4.position (): get the current position of the mouse pointer' '' 
Print ( "Get the current mouse location:", pyautogui.position ()) 

'' '5.click (): for controlling a mouse click and drag '' ' 
pyautogui.click (370, 120) 
a doubleClick () Double-click 
a rightClick () Right-click 

"" " 
6. there is a mouse drag operation associated with two functions: dragTo and dragRel thereof. moveTo and moveRel behavior and the like, 
except that the drag operation in the process of moving, holding the left mouse button will be pressed.
This feature can be used in different scenarios, such as a mobile box, or pencil tool automatically drawing program drawing board with Windows 
"" "  
Import pyautogui
Import Time
time.sleep (5) # 5 seconds time to switch to the program Artboards 

pyautogui.moveTo (200, 200, duration = 1) # moves the mouse (200, 200) a position 
pyautogui.dragRel (100, 0, duration = 1) # opposing mobile 
pyautogui.dragRel (0, 100, duration = 1) # relative movement 
pyautogui.dragRel (-100, 0, duration = 1) # relative movement 
pyautogui.dragRel (0, -100, duration = 1) # relative movement 


"" "7.scroll (): number of pixels of scrolling function accepts number of pixels as an argument, and with the given upward scrolling" "" 
pyautogui.scroll (200 is) rolled back up # 
# scrolling of the selected window 200 when the pixels up. when the value is negative, move down 

'' '8. typewrite (): for automatic type string, the string will simply be passed to the function type as a parameter to' '' 
pyautogui.click (1000,400) 
pyautogui .typewrite ( "Word Hello!") 
# text area assumed positions of the screen at coordinates (100, 200), then this code will click the text area, activate it, and type 'Word Hello! 
 
"" "9. the transfer key name:Can to typewrite () function is passed separate keys. "" "
pyautogui.typewrite ([' a ' , 'left', 'ctrlleft']) 
# Code is equivalent to: type "a", and then tap the left direction key, and then tap the left ctrl key.

"" "10 hotkey combination: hotkey () can simulate hot key combination, such as: ctrl-c, ctrl-a , ctrl-v , etc." "" 
# 1. Analog ctrl-v, replication 
pyautogui.hotkey ( ' ctrlleft ',' V ') 
# is equivalent to 
pyautogui.keyDown (' Ctrl ') 
pyautogui.keyDown ( "Shift") 
pyautogui.keyDown (' ESC ') 
pyautogui.keyUp (' ESC ') 
pyautogui.keyUp (' Shift ' ) 
pyautogui.keyUp ( 'Ctrl') 

"" "11.press (): function keys keyboard" "" 
pyautogui.press ( "enter") # a keyboard input ENTR 
pyautogui.press ( "F1") # Press The Key Fl 
pyautogui.press ( "left") # left arrow key 

"" "message pop function" ""
# If you need to pop the message by clicking OK to pause the program or to display some information to the user, a message will pop function of JavaScript has a similar function: 
pyautogui.alert ( 'This is a text message pop + OK button ') # returns OK
pyautogui.confirm ( 'the news click OK') # returns the input string pop text + OK + Cancel button ') # returns OK or the Cancel 
pyautogui.prompt (' the news popups allow users to input string, click OK ') # returns the input string

  

 

Guess you like

Origin www.cnblogs.com/feifeifeisir/p/10967685.html