4

Is it possible to run PyAutoGUI in headless in windows 7 using Universal Termsrv.dll ,creating multi seats ?

Aju
  • 503
  • 1
  • 8
  • 26
guiboy
  • 101
  • 1
  • 10

3 Answers3

4

It is now possible to use PyAutoGUI in the headless mode. All you need to do is provide a path to PyAutoGUI for virtual display. This process will run in the background and there will be no actual display. This method can also be used for using PyAutoGUI in docker as well.

Code:

import pyautogui
import os
from pyvirtualdisplay.display import Display
import Xlib.display


disp = Display(visible=True, size=(1920,1080), backend="xvfb", use_xauth=True)
disp.start()

pyautogui._pyautogui_x11._display = Xlib.display.Display(os.environ['DISPLAY'])
...
fam
  • 583
  • 3
  • 14
  • Can you expand the code to have an example? And with which Python version it works? – Saeed Oct 21 '22 at 20:14
  • 1
    I have tested it with python==3.8 and pyAutoGUI==0.9.53. I was using selenium and docker. Can you please be exact about your requirement and provide additional information regarding what you want to do and I will try my best to provide a detailed answer. – fam Oct 24 '22 at 06:52
  • Thanks, I'm trying to click somewhere with mouse without cursor being moved, and I'm not sure if your answer is what I want. Like Selenium that clicks on an element, I want to click with `pyautogui` but in a Desktop application, like calculator or notepad. – Saeed Oct 24 '22 at 06:58
  • Sorry, I have not specifically worked on this problem. However, you can use `pyautogui.moveTo(x-coord, y-coord)` and `pyautogui.click()` to move your cursor on a specific position and perform automatic click action without moving the cursor. You can find additional information here: https://pyautogui.readthedocs.io/en/latest/mouse.html Let me know if you want to discuss more details. – fam Oct 24 '22 at 07:05
2

It is not possible to run PyAutoGUI in headless mode or on a remote desktop.

This feature is on the roadmap, but there is no timeline or resources dedicated to it.

But, as a workaround, you can use xvfb-run aka Virtual Framebuffer 'fake' X server:

xvfb-run python PyAutoGUI-script.py
Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223
Al Sweigart
  • 11,566
  • 10
  • 64
  • 92
  • Do you have source link? Is it still applicable in 2023? – Gilles Quénot May 19 '23 at 16:34
  • I'm the maintainer of PyAutoGUI, and can confirm that in 2023 it still does not have a headless mode. – Al Sweigart May 21 '23 at 16:49
  • do PyautoGUI is ok to run with `xvfb-run` (aka `Virtual Framebuffer 'fake' X server`) ? I use it with Python Selenium + PyautoGUI in headless mode, see https://stackoverflow.com/a/75913141/465183 I guess yes, as far as my mouse move in headless mode. Edited your POST, tell me if I'm wrong. – Gilles Quénot May 21 '23 at 19:26
0

A simplest way:

xvfb-run python ./selenium-script.py

No need:

from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 600))
display.start()
display.stop()
Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223