如何将pyautogui附加到虚拟显示器? [英] How to attach pyautogui to the virtual display?

查看:121
本文介绍了如何将pyautogui附加到虚拟显示器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在多线程模式下将 pyautogui 附加到显示器?

How do I attach pyautogui to the display in multithreaded mode?

在我的代码示例中,pyautogui 始终可以访问上部显示.

In the example of my code, pyautogui always has access to the upper display.

是否可以在每个显示器上都有 pyautogui 控件?

Is it possible to have pyautogui control on each display?

import os
from selenium import webdriver
from pyvirtualdisplay import Display
import Xlib.display
# ...

# let's say i run this function in two threads
def do_work(data):
    v_display = Display(visible=0, size=(900, 600))
    v_display.start()

    # How can i attach v_display to the pyautogui?
    import pyautogui

    print(v_display)
    # https://stackoverflow.com/questions/35798478/how-i-can-attach-the-mouse-movement-pyautogui-to-pyvirtualdisplay-with-seleniu
    pyautogui._pyautogui_x11._display = Xlib.display.Display(os.environ['DISPLAY'])

    print(pyautogui._pyautogui_x11._display)

    chrome_options = Options()
    chrome_options.add_argument('--user-data-dir='+str(data['profile']))
    chrome_options.add_argument("--start-maximized")


    driver = webdriver.Chrome('chromedriver', chrome_options=chrome_options)

    driver.get('https://my_resource.co/?'+data['param'])


    pyautogui.click(x=880, y=580)
    # Click always goes through the upper display
    # I also tried to take screenshots they are always the same

    # ...

    driver.quit()
    v_display.stop()

输出:

<Display cmd_param=['Xvfb', '-br', '-nolisten', 'tcp', '-screen', '0', '900x600x24', ':1086'] cmd=['Xvfb', '-br', '-nolisten', 'tcp', '-screen', '0', '900x600x24', ':1086'] oserror=None return_code=None stdout="None" stderr="None" timeout_happened=False>
<Display cmd_param=['Xvfb', '-br', '-nolisten', 'tcp', '-screen', '0', '900x600x24', ':1087'] cmd=['Xvfb', '-br', '-nolisten', 'tcp', '-screen', '0', '900x600x24', ':1087'] oserror=None return_code=None stdout="None" stderr="None" timeout_happened=False>
<Xlib.display.Display object at 0x7f4f5493aa90>
<Xlib.display.Display object at 0x7f4f5493a8d0>

附注
我知道如何通过 selenium 进行点击,但我完全需要 pyautogui 事件.

P.S.
I know how to make clicks through selenium, but I need exactly pyautogui events.

推荐答案

来自 https 的 pyautogui 文档://pyautogui.readthedocs.io/en/latest/ :

Q: Does PyAutoGUI work on multi-monitor setups.
A: No, right now PyAutoGUI only handles the primary monitor.

这篇关于如何将pyautogui附加到虚拟显示器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆