pyautogui
A cross-platform GUI automation Python module for human beings. Used to programmatically control the mouse & keyboard.
Science Score: 23.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
○.zenodo.json file
-
○DOI references
-
○Academic publication links
-
✓Committers with academic emails
1 of 52 committers (1.9%) from academic institutions -
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (13.7%) to scientific vocabulary
Keywords from Contributors
Repository
A cross-platform GUI automation Python module for human beings. Used to programmatically control the mouse & keyboard.
Basic Info
Statistics
- Stars: 11,768
- Watchers: 193
- Forks: 1,351
- Open Issues: 565
- Releases: 0
Metadata Files
README.md
PyAutoGUI
PyAutoGUI is a cross-platform GUI automation Python module for human beings. Used to programmatically control the mouse & keyboard.
pip install pyautogui
Full documentation available at https://pyautogui.readthedocs.org
Simplified Chinese documentation available at https://github.com/asweigart/pyautogui/blob/master/docs/simplified-chinese.ipynb
Source code available at https://github.com/asweigart/pyautogui
If you need help installing Python, visit https://installpython3.com/
Dependencies
PyAutoGUI supports Python 2 and 3. If you are installing PyAutoGUI from PyPI using pip:
Windows has no dependencies. The Win32 extensions do not need to be installed.
macOS needs the pyobjc-core and pyobjc module installed (in that order).
Linux needs the python3-xlib (or python-xlib for Python 2) module installed.
Pillow needs to be installed, and on Linux you may need to install additional libraries to make sure Pillow's PNG/JPEG works correctly. See:
https://stackoverflow.com/questions/7648200/pip-install-pil-e-tickets-1-no-jpeg-png-support
http://ubuntuforums.org/showthread.php?t=1751455
If you want to do development and contribute to PyAutoGUI, you will need to install these modules from PyPI:
- pyscreeze
- pymsgbox
- pytweening
Example Usage
Keyboard and Mouse Control
The x, y coordinates used by PyAutoGUI has the 0, 0 origin coordinates in the top left corner of the screen. The x coordinates increase going to the right (just as in mathematics) but the y coordinates increase going down (the opposite of mathematics). On a screen that is 1920 x 1080 pixels in size, coordinates 0, 0 are for the top left while 1919, 1079 is for the bottom right.
Currently, PyAutoGUI only works on the primary monitor. PyAutoGUI isn't reliable for the screen of a second monitor (the mouse functions may or may not work on multi-monitor setups depending on your operating system and version).
All keyboard presses done by PyAutoGUI are sent to the window that currently has focus, as if you had pressed the physical keyboard key.
python
>>> import pyautogui
>>> screenWidth, screenHeight = pyautogui.size() # Returns two integers, the width and height of the screen. (The primary monitor, in multi-monitor setups.)
>>> currentMouseX, currentMouseY = pyautogui.position() # Returns two integers, the x and y of the mouse cursor's current position.
>>> pyautogui.moveTo(100, 150) # Move the mouse to the x, y coordinates 100, 150.
>>> pyautogui.click() # Click the mouse at its current location.
>>> pyautogui.click(200, 220) # Click the mouse at the x, y coordinates 200, 220.
>>> pyautogui.move(None, 10) # Move mouse 10 pixels down, that is, move the mouse relative to its current position.
>>> pyautogui.doubleClick() # Double click the mouse at the
>>> pyautogui.moveTo(500, 500, duration=2, tween=pyautogui.easeInOutQuad) # Use tweening/easing function to move mouse over 2 seconds.
>>> pyautogui.write('Hello world!', interval=0.25) # Type with quarter-second pause in between each key.
>>> pyautogui.press('esc') # Simulate pressing the Escape key.
>>> pyautogui.keyDown('shift')
>>> pyautogui.write(['left', 'left', 'left', 'left', 'left', 'left'])
>>> pyautogui.keyUp('shift')
>>> pyautogui.hotkey('ctrl', 'c')
Display Message Boxes
python
>>> import pyautogui
>>> pyautogui.alert('This is an alert box.')
'OK'
>>> pyautogui.confirm('Shall I proceed?')
'Cancel'
>>> pyautogui.confirm('Enter option.', buttons=['A', 'B', 'C'])
'B'
>>> pyautogui.prompt('What is your name?')
'Al'
>>> pyautogui.password('Enter password (text will be hidden)')
'swordfish'
Screenshot Functions
(PyAutoGUI uses Pillow for image-related features.)
python
>>> import pyautogui
>>> im1 = pyautogui.screenshot()
>>> im1.save('my_screenshot.png')
>>> im2 = pyautogui.screenshot('my_screenshot2.png')
You can also locate where an image is on the screen:
python
>>> import pyautogui
>>> button7location = pyautogui.locateOnScreen('button.png') # returns (left, top, width, height) of matching region
>>> button7location
(1416, 562, 50, 41)
>>> buttonx, buttony = pyautogui.center(button7location)
>>> buttonx, buttony
(1441, 582)
>>> pyautogui.click(buttonx, buttony) # clicks the center of where the button was found
The locateCenterOnScreen() function returns the center of this match region:
python
>>> import pyautogui
>>> buttonx, buttony = pyautogui.locateCenterOnScreen('button.png') # returns (x, y) of matching region
>>> buttonx, buttony
(1441, 582)
>>> pyautogui.click(buttonx, buttony) # clicks the center of where the button was found
How Does PyAutoGUI Work?
The three major operating systems (Windows, macOS, and Linux) each have different ways to programmatically control the mouse and keyboard. This can often involve confusing, obscure, and deeply technical details. The job of PyAutoGUI is to hide all of this complexity behind a simple API.
On Windows, PyAutoGUI accesses the Windows API (also called the WinAPI or win32 API) through the built-in
ctypesmodule. Thenicewinmodule at https://github.com/asweigart/nicewin provides a demonstration for how Windows API calls can be made through Python.On macOS, PyAutoGUI uses the
rubicon-objcmodule to access the Cocoa API.On Linux, PyAutoGUI uses the
Xlibmodule to access the X11 or X Window System.
Support
If you find this project helpful and would like to support its development, consider donating to its creator on Patreon.
Owner
- Name: Al Sweigart
- Login: asweigart
- Kind: user
- Location: USA
- Website: https://github.com/asweigart/readal
- Twitter: AlSweigart
- Repositories: 239
- Profile: https://github.com/asweigart
Author of "Automate the Boring Stuff with Python" and other free coding books. he/him
Committers
Last synced: 9 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Al Sweigart | a****t@g****m | 220 |
| Denilson Sá | d****a@g****m | 16 |
| Junjie Tao | t****j@1****m | 7 |
| Hugo Salvador | h****b@g****m | 6 |
| jose1711 | j****1@g****m | 4 |
| HesselM | h****e@g****m | 4 |
| Jeromie Kirchoff | j****4@g****m | 4 |
| karimk123 | 6****3 | 3 |
| Scott Noyes | s****s@g****m | 3 |
| Andy Dam | a****y@a****m | 3 |
| Daniel D. Beck | me@d****m | 2 |
| Stefan Hoelzl | s****l@p****e | 2 |
| Fornost461 | F****1 | 2 |
| Kudria | k****5@g****m | 2 |
| Martin Michlmayr | t****m@c****m | 2 |
| Abhijeet Singh | c****h@g****m | 2 |
| Alghost | a****t@m****r | 1 |
| RMPR | a****o@g****m | 1 |
| Nik Schewtschuk | n****e@g****m | 1 |
| Anwar A. Ruff | a****f@g****m | 1 |
| Ashok Fernandez | a****z@g****m | 1 |
| Davee Nguyen | d****e@d****m | 1 |
| Dominik Schmelz | d****k@s****c | 1 |
| ErtugrulSener | e****r@h****e | 1 |
| Harish Chandran | h****4@g****m | 1 |
| Jeremy R. Gray | j****y@g****m | 1 |
| nexcvon | n****n | 1 |
| mvbentes | g****b@b****m | 1 |
| liberme | l****e | 1 |
| johnborgmann | 8****n | 1 |
| and 22 more... | ||
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 255
- Total pull requests: 53
- Average time to close issues: 8 months
- Average time to close pull requests: over 1 year
- Total issue authors: 238
- Total pull request authors: 46
- Average comments per issue: 3.12
- Average comments per pull request: 0.79
- Merged pull requests: 1
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 39
- Pull requests: 17
- Average time to close issues: 8 days
- Average time to close pull requests: 3 minutes
- Issue authors: 37
- Pull request authors: 12
- Average comments per issue: 0.44
- Average comments per pull request: 0.12
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- asweigart (9)
- me-suzy (2)
- DevYuriOliveira73 (2)
- ORB-Aerospace911 (2)
- executionByFork (2)
- Wintecks (2)
- wiktorlaskowski (2)
- samshum (2)
- Avasam (2)
- DataMower (2)
- killerwhite (2)
- wangmings (1)
- kotmotok (1)
- erikji (1)
- CodeBuzz-ML (1)
Pull Request Authors
- Avasam (3)
- Jarno-de-Wit (2)
- Sandesh-AT-GitHub (2)
- djalan (2)
- fredfurst (2)
- LAbhilashKumar (2)
- yahya-ali28 (2)
- Mascantosh (2)
- ivanmilevtues (2)
- stribus (2)
- calvindo95 (2)
- roshanjain77 (2)
- davide710 (2)
- Desyncfy (2)
- spacewaterbear (2)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 4
-
Total downloads:
- pypi 1,472,787 last-month
- Total docker downloads: 415,358
-
Total dependent packages: 326
(may contain duplicates) -
Total dependent repositories: 1,031
(may contain duplicates) - Total versions: 65
- Total maintainers: 2
pypi.org: pyautogui
PyAutoGUI lets Python control the mouse and keyboard, and other GUI automation tasks. For Windows, macOS, and Linux, on Python 3 and 2.
- Homepage: https://github.com/asweigart/pyautogui
- Documentation: https://pyautogui.readthedocs.io/
- License: BSD
-
Latest release: 0.9.54
published almost 3 years ago
Rankings
Maintainers (1)
pypi.org: pyautoguiumlauts
PyAutoGUI lets Python control the mouse and keyboard, and other GUI automation tasks. For Windows, macOS, and Linux, on Python 3 and 2.
- Homepage: https://github.com/asweigart/pyautogui
- Documentation: https://pyautoguiumlauts.readthedocs.io/
- License: BSD
-
Latest release: 0.9.51
published over 5 years ago
Rankings
pypi.org: pyautogui-soraban
PyAutoGUI lets Python control the mouse and keyboard, and other GUI automation tasks. For Windows, macOS, and Linux, on Python 3 and 2.
- Homepage: https://github.com/asweigart/pyautogui
- Documentation: https://pyautogui-soraban.readthedocs.io/
- License: BSD
-
Latest release: 0.9.56
published over 1 year ago
Rankings
Maintainers (1)
conda-forge.org: pyautogui
- Homepage: https://github.com/asweigart/pyautogui
- License: BSD-3-Clause
-
Latest release: 0.9.53
published over 4 years ago
Rankings
Dependencies
- pillow *
- pyautogui *
- pytest *
- mouseinfo *
- pygetwindow >=0.0.5
- pymsgbox *
- pyobjc *
- pyobjc-core *
- pyscreeze >=0.1.21
- python-xlib *
- python3-Xlib *
- pytweening >=1.0.4