Debian Codegraph @

docs/index.rst

raw
1 .. PyAutoGUI documentation master file, created by
2 sphinx-quickstart on Sun Jul 20 12:59:43 2014.
3 You can adapt this file completely to your liking, but it should at least
4 contain the root `toctree` directive.
5
6 Welcome to PyAutoGUI's documentation!
7 =====================================
8
9
10 PyAutoGUI lets your Python scripts control the mouse and keyboard to automate interactions with other applications. The API is designed to be simple. PyAutoGUI works on Windows, macOS, and Linux, and runs on Python 2 and 3.
11
12 To install with pip, run ``pip install pyautogui``. See the :doc:`install` page for more details.
13
14 The source code is available on: https://github.com/asweigart/pyautogui
15
16 PyAutoGUI has several features:
17
18 * Moving the mouse and clicking in the windows of other applications.
19 * Sending keystrokes to applications (for example, to fill out forms).
20 * Take screenshots, and given an image (for example, of a button or checkbox), and find it on the screen.
21 * Locate an application's window, and move, resize, maximize, minimize, or close it (Windows-only, currently).
22 * Display alert and message boxes.
23
24 Here's `a YouTube video of a bot automatically playing the game Sushi Go Round <https://www.youtube.com/watch?v=lfk_T6VKhTE>`_. The bot watches the game's application window and searches for images of sushi orders. When it finds one, it clicks the ingredient buttons to make the sushi. It also clicks the phone in the game to order more ingredients as needed. The bot is completely autonomous and can finish all seven days of the game. This is the kind of automation that PyAutoGUI is capable of.
25
26 Examples
27 ========
28
29 .. code:: python
30
31 >>> import pyautogui
32
33 >>> screenWidth, screenHeight = pyautogui.size() # Get the size of the primary monitor.
34 >>> screenWidth, screenHeight
35 (2560, 1440)
36
37 >>> currentMouseX, currentMouseY = pyautogui.position() # Get the XY position of the mouse.
38 >>> currentMouseX, currentMouseY
39 (1314, 345)
40
41 >>> pyautogui.moveTo(100, 150) # Move the mouse to XY coordinates.
42
43 >>> pyautogui.click() # Click the mouse.
44 >>> pyautogui.click(100, 200) # Move the mouse to XY coordinates and click it.
45 >>> pyautogui.click('button.png') # Find where button.png appears on the screen and click it.
46
47 >>> pyautogui.move(400, 0) # Move the mouse 400 pixels to the right of its current position.
48 >>> pyautogui.doubleClick() # Double click the mouse.
49 >>> pyautogui.moveTo(500, 500, duration=2, tween=pyautogui.easeInOutQuad) # Use tweening/easing function to move mouse over 2 seconds.
50
51 >>> pyautogui.write('Hello world!', interval=0.25) # type with quarter-second pause in between each key
52 >>> pyautogui.press('esc') # Press the Esc key. All key names are in pyautogui.KEY_NAMES
53
54 >>> with pyautogui.hold('shift'): # Press the Shift key down and hold it.
55 pyautogui.press(['left', 'left', 'left', 'left']) # Press the left arrow key 4 times.
56 >>> # Shift key is released automatically.
57
58 >>> pyautogui.hotkey('ctrl', 'c') # Press the Ctrl-C hotkey combination.
59
60 >>> pyautogui.alert('This is the message to display.') # Make an alert box appear and pause the program until OK is clicked.
61
62 This example drags the mouse in a square spiral shape in MS Paint (or any graphics drawing program):
63
64 .. code:: python
65
66 >>> distance = 200
67 >>> while distance > 0:
68 pyautogui.drag(distance, 0, duration=0.5) # move right
69 distance -= 5
70 pyautogui.drag(0, distance, duration=0.5) # move down
71 pyautogui.drag(-distance, 0, duration=0.5) # move left
72 distance -= 5
73 pyautogui.drag(0, -distance, duration=0.5) # move up
74
75 .. image:: square_spiral.png
76
77 The benefit of using PyAutoGUI, as opposed to a script that directly generates the image file, is that you can use the brush tools that MS Paint provides.
78
79 FAQ: Frequently Asked Questions
80 ===============================
81
82 Send questions to [email protected]
83
84 **Q: Can PyAutoGUI work on Android, iOS, or tablet/smartphone apps.**
85
86 A: Unfortunately no. PyAutoGUI only runs on Windows, macOS, and Linux.
87
88 **Q: Does PyAutoGUI work on multi-monitor setups.**
89
90 A: No, right now PyAutoGUI only handles the primary monitor.
91
92 **Q: Does PyAutoGUI do OCR?**
93
94 A: No, but this is a feature that's on the roadmap.
95
96 **Q: Can PyAutoGUI do keylogging, or detect if a key is currently pressed down?**
97
98 A: No, PyAutoGUI cannot do this currently.
99
100
101 Fail-Safes
102 ==========
103
104 .. image:: sorcerers_apprentice_brooms.png
105
106 Like the enchanted brooms from the Sorcerer’s Apprentice programmed to keep filling (and then overfilling) the bath with water, a bug in your program could make it go out of control. It's hard to use the mouse to close a program if the mouse cursor is moving around on its own.
107
108 As a safety feature, a fail-safe feature is enabled by default. When a PyAutoGUI function is called, if the mouse is in any of the four corners of the primary monitor, they will raise a ``pyautogui.FailSafeException``. There is a one-tenth second delay after calling every PyAutoGUI functions to give the user time to slam the mouse into a corner to trigger the fail safe.
109
110 You can disable this failsafe by setting ``pyautogui.FAILSAFE = False``. **I HIGHLY RECOMMEND YOU DO NOT DISABLE THE FAILSAFE.**
111
112 The tenth-second delay is set by the ``pyautogui.PAUSE`` setting, which is ``0.1`` by default. You can change this value. There is also a ``pyautogui.DARWIN_CATCH_UP_TIME`` setting which adds an additional delay on macOS after keyboard and mouse events, since the operating system appears to need a delay after PyAutoGUI issues these events. It is set to ``0.01`` by default, adding an additional hundredth-second delay.
113
114
115 Contents:
116
117 .. toctree::
118 :maxdepth: 2
119
120 install.rst
121 quickstart.rst
122 mouse.rst
123 keyboard.rst
124 msgbox.rst
125 screenshot.rst
126 tests.rst
127 roadmap.rst
128
129 source/modules.rst
130
131 This documentation is still a work in progress.
132
133
134 Indices and tables
135 ==================
136
137 * :ref:`genindex`
138 * :ref:`modindex`
139 * :ref:`search`
140