How do I get autopygui and pyglet to work together?

跟風遠走 提交于 2020-12-13 10:37:21

问题


Getting a conflict between pyglet and autopygui, when one is running I can't use the other. I found a few things online but no one has posted a resolution to the problem.

ctypes.ArgumentError: argument 1: <class 'TypeError'>: expected LP_POINT instance instead of pointer to POINT

https://github.com/asweigart/pyautogui/issues/26 https://code.google.com/archive/p/pyglet/issues/559

This has been fixed together with issue 510 in rev. e46762382a3

Said to be resolved in that link but I'm still having the issue.

https://bitbucket.org/pyglet/pyglet/issues/95/pyglet-error-with-lp_point-pyautogui


回答1:


We had the same issue, which seems to arise when autopygui makes the mouse click.

If you can import an additional libary, here's a possible workaround: you may use autopygui to locate an image on the screen and another library to make the mouse 'click'. For example:

import ctypes
import pyautogui

def click_mouse_at(pos):
    pos_x, pos_y = int(pos[0]), int(pos[1])
    ctypes.windll.user32.SetCursorPos(pos_x, pos_y)
    ctypes.windll.user32.mouse_event(2, 0, 0, 0,0) 
    ctypes.windll.user32.mouse_event(4, 0, 0, 0,0)
    
def get_centre(a_box):
    ''' return centre of an image '''
    return a_box[0]+a_box[2]/2, a_box[1]+a_box[3]/2

an_img_file_path = ..path to your image file..
click_mouse_at(get_centre(pyautogui.locateOnScreen(an_img_file_path)))

Tested on Windows10 and seems to work



来源:https://stackoverflow.com/questions/45900685/how-do-i-get-autopygui-and-pyglet-to-work-together

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!