Questions tagged [pyautogui]

PyAutoGUI is a cross-platform GUI automation Python module used to programmatically control the mouse and keyboard.

Official document.

PyAutoGUI lets your Python scripts control the mouse and keyboard to automate interactions with other applications. The API is designed to be as simple. PyAutoGUI works on Windows, macOS, and Linux, and runs on Python 2 and 3.

PyAutoGUI has several features:

  • Moving the mouse and clicking or typing in the windows of other applications.
  • Sending keystrokes to applications (for example, to fill out forms).
  • Take screenshots, and given an image (for example, of a button or checkbox), find it on the screen.
  • Locate an application’s window, and move, resize, maximize, minimize, or close it (Windows-only, currently) Display message boxes for user interaction while your GUI automation script runs.
1828 questions
27
votes
3 answers

Python pyautogui window handle

Using pyautogui is there a way to get a handle to a window so that I can ensure that a click is performed on that window only? In other words, if my window isn't in focus, then the click does not occur. Additionally, if my window isn't in focus then…
kronosjt
  • 703
  • 4
  • 10
  • 24
26
votes
15 answers

Why PyAutoGui LocateOnScreen() only Returns None

Here's the code that I'm trying to run: import pyautogui r=pyautogui.locateOnScreen('C:\Users\David\Desktop\index.png',grayscale=False) print r
Raheem
  • 482
  • 1
  • 4
  • 8
24
votes
2 answers

Can pyautogui be used to prevent windows screen lock?

I tried to use this script to prevent windows screen lock. The script works for moving the mouse, but it doesn't prevent windows 10 from locking. import pyautogui import time import win32gui, win32con import os Minimize =…
Python account
  • 427
  • 1
  • 5
  • 15
21
votes
4 answers

Pyautogui: Mouse Movement with bezier curve

I'm trying to move the mouse in a bezier curve motion in Pyautogui to simulate more of a human movement as seen here: There is some tweening / easing functions within pyautogui but none of which represent a bezier curve type movement. I created a…
ahinkle
  • 2,117
  • 3
  • 29
  • 58
21
votes
9 answers

pyautogui.locateCenterOnScreen() returns None instead of coordinates

import pyautogui print (pyautogui.locateCenterOnScreen("C:\Users\Venkatesh_J\PycharmProjects\mouse_event\mouse_event.png")) Instead of returning coordinates, it returns None.
Venkatesh J
  • 211
  • 1
  • 2
  • 7
20
votes
5 answers

import error for pyautogui

I installed the pyautogui module and dependencies via pip-3.2 on my raspi correctly, However when I am trying to do import pyautogui I am getting an import error: ImportError: No module named pyautogui What am I doing wrong? Did the command…
Nixxon
  • 201
  • 1
  • 2
  • 8
16
votes
5 answers

Copy highlighted text to clipboard, then use the clipboard to append it to a list

I'm trying to automate some actions in a browser or a word processor with pyautogui module for Python 3 (Windows 10). There is a highlighted text in a browser. text the following script should print the highlighted text import pyautogui as pya #…
Stefan Smirnov
  • 695
  • 3
  • 6
  • 18
15
votes
2 answers

How do I detect a keypress event with PyAutoGUI?

How do I use PyAutoGUI to detect a keypress event? In my research, I could not make an example in this model: import pyautogui num = 0 if pyautogui.press('b'): # I know the right thing is not to use the press, but, what do I put in place? num =…
Mi Tavares
  • 161
  • 1
  • 1
  • 5
14
votes
3 answers

How can I invert the cursor movement in python?

In this code, I'm using Python 2.7.13, OpenCV 2.4.13 and PyAutoGUI 0.9.36. The objective is to move the cursor according to the facial movement, but the cursor movement is inverted. For example, if my face goes to right, the cursor moves to left and…
TigerC
  • 161
  • 6
14
votes
6 answers

Input unicode string with pyautogui

I'm creating an autotesting app with pyautogui lib. I want to use typewrite method to input text into forms. But some of my input strings have unicode characters in them. For example: Næst According to documentation typewrite can only press…
testlnord
  • 438
  • 1
  • 5
  • 14
13
votes
2 answers

Pyautogui screenshot - NameError: name 'Image' is not defined

I'm trying to use pyautogui's screenshot functions with Python 3.6.5 on OSX 10.11. >>> import pyautogui >>> image = pyautogui.screenshot() I get: Traceback (most recent call last): File "", line 1, in File…
11
votes
1 answer

Pyautogui does not move the actual mouse pointer

I've been having a problem with pyautogui. Anytime I use the functions, it works, but it uses an "invisible" mouse pointer. Basically the module doesn't use the mouse to click things, but they still click and drag. Here's a visual example: Reading…
ExecutionByFork
  • 206
  • 1
  • 5
  • 19
11
votes
7 answers

How to control the mouse in Minecraft using Python?

All in all, I'm trying to programmatically -and externally- control the Minecraft player's orientation. No APIs, no Java mods to the game environment Typically this requires the movement of the mouse, but every single mouse movement simulating…
pizzafoot
  • 125
  • 1
  • 1
  • 8
11
votes
2 answers

Speeding up pyautogui screenshot() with region

I'm trying to speed up the screenshot function in pyautogui since I only need a small portion of the screen. The region variable is supposedly the way to this a.k.a. pyautogui.screenshot(region=(0,0,400,300)). However after doing some testing I…
Sindri Ingolfsson
  • 135
  • 1
  • 1
  • 7
11
votes
5 answers

How to print out 'Live' mouse position coordinates using pyautogui?

I used lots of different source codes, and even copied and pasted but I keep getting random symbols that shift when i move my mouse over them here is my code... import pyautogui, time, sys print('Press Ctrl-C to quit.') try: while True: …
SovietStormSam
  • 123
  • 1
  • 1
  • 7
1
2 3
99 100