Brief introduction of python programming PyAutoGUI library use and installation

  • 2021-12-05 06:35:05
  • OfStack

How to free hands through python code, or to realize automatic computer mouse or keyboard operation through code?

The PyAutoGUI library of python is a good choice.

First download PyAutoGUI from the following website

https://pypi.org/project/PyAutoGUI/

Because IDE of python is Pycharm, enter the following code in terminal of Pycharm:

pip install PyAutoGUI

Installation successful ~ ~

Then import PyAutoGUI in Pycharm setting project interprer. If you don't find it, you can use it directly without importing it.

Here's a small example:


import pyautogui as pg
import time
#  Close this python Interface 
pg.moveTo(3650,10)
pg.click()
# That runs the script python Interface 
pg.moveTo(3570,60)
pg.click()
time.sleep(2)
#  Close this python Interface 
pg.moveTo(3650,10)
pg.click()
# Import script 
pg.moveTo(2400,410)
pg.rightClick()
pg.moveTo(2500,700)
pg.click()
#  Select the script 
pg.moveTo(1200,300)
pg.click()
pg.moveTo(1200,980)
pg.click()
#  Pause a little 1 Under 
time.sleep(1)
# Drag and drop global variables 
pg.moveTo(3100,300)
time.sleep(1)
pg.drag(-900,-70,duration=2)
#  Start playing 
pg.moveTo(1830,97)
pg.click()

Among them

pg.click() Means clicking the mouse,

pg.moveTo(x,y) Represents moving to a position on the computer screen.

time The function of library is to delay mouse or keyboard operation,

pg.drag (x, y, duration =...) Used to implement the mouse drag operation.

The work of keyboard calls interested children's shoes, which can be Baidu 1 by themselves. With the above functions, 1 while cycle, just a few words you can use the computer to chat with friends automatically (although only a few fixed words, hahaha), and then I use this to realize 1 automatic drag-and-drop mouse, help me save files and run small scripts of the project, liberate my hands, and look at the completion speed of the computer, which is indeed faster than my hand speed. Anyway, python- > nb ~ Video Achievement Display:

PyAutoGUI usage demonstration

The above is the python programming PyAutoGUI library use and installation introduction details, more about PyAutoGUI library use and installation information please pay attention to other related articles on this site!


Related articles: