asweigart/pyautogui là dự án mã nguồn mở trên GitHub, viết chủ yếu bằng Python, với 12.8k sao. A cross-platform GUI automation Python module for human beings. Used to programmatically control the mouse & keyboard.
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
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.
>>> 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
>>> 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.)
You can also locate where an image is on the screen:
>>> 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:
>>> 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 ctypes module. The nicewin module 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-objc module to access the Cocoa API.
On Linux, PyAutoGUI uses the Xlib module 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.
asweigart/pyautogui có 12.8k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/asweigart/pyautogui. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
asweigart/pyautogui có tag gì không?
Bản đồng bộ chưa ghi nhận topic GitHub nào cho asweigart/pyautogui. GitHub topics hiển thị ở thanh bên phải trang repo — đó là nơi đáng kiểm tra nhất.
asweigart/pyautogui có website riêng không?
TopGit chưa ghi nhận URL trang chủ cho asweigart/pyautogui. Phần README ở tab phía trên thường có link demo, hoặc xem mô tả GitHub của repo.
asweigart/pyautogui còn đang phát triển không?
Commit gần nhất trên asweigart/pyautogui là 2.2 năm trước (theo timestamp GitHub). Repo có 1.4k fork — một chỉ báo về mức độ quan tâm của cộng đồng.
asweigart/pyautogui dùng license gì?
asweigart/pyautogui phát hành theo license BSD-3-Clause. Nên mở file LICENSE trên GitHub để xác nhận — license metadata đôi khi lệch với thực tế dự án.
asweigart/pyautogui viết bằng ngôn ngữ gì?
asweigart/pyautogui chủ yếu viết bằng Python. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc thêm về asweigart/pyautogui ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/asweigart/pyautogui là nguồn chính thức.
Đọc đầy đủ README ở tab phía trên.
Muốn nghe thêm một ý kiến về pyautogui?
Hỏi một AI đọc được trang này — một cú bấm là có ngay nhận định về pyautogui.