ponty / PyVirtualDisplay

Python wrapper for Xvfb, Xephyr and Xvnc
BSD 2-Clause "Simplified" License
714 stars 78 forks source link

Send mouse and keyboard inputs #55

Closed Karol-G closed 4 years ago

Karol-G commented 4 years ago

Hi,

I want to automate a little program. However when using PyAutoGui for sending key strokes and moving/clicking with the mouse the actions happen on my real display and not the virtual one. How can I achieve that these events are executed inside the virtual display? I tried vncdotool already, however the application seems to be not really supported/working anymore :(

Best Karol

zorvios commented 4 years ago

Hi @Karol-G I had the same issue before, you have to import the PyAutoGui after starting your virtual Display not before.

Karol-G commented 4 years ago

Hi, thanks for the extremly quick answer 👍 It works now. I started the virtual display in a function so I had to define the import as global:

def setup_headless(self):
    if self.headless:
        disp = Display(visible=False, size=(1000, 1300)).start()
        global pyautogui
        import pyautogui

Best Karol