win32gui点击Bluestacks中的坐标
我正在尝试在BlueStacks中自动化一个过程,在该过程中,我等待元素出现在屏幕上,当它出现时,单击它。除了点击部分外,一切都有效,我已经做了很多研究并尝试了不同的事情,但是我无法正常工作。
我知道我可以使用pyautogui轻松做到这一点,但是我不想使程序移动实际光标,关键功能之一是它可以运行而无需将窗口放在前景上(不要集中精力窗户)。
def compare_images():
threshold = 0.80
i = -1
width = 0
height = 0
mouse_x = 0
mouse_y = 0
for template in templates:
i += 1
result_image = cv2.matchTemplate(scr, template, cv2.TM_CCOEFF_NORMED)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result_image)
width = templates[i].shape[1]
height = templates[i].shape[0]
if max_val > threshold:
# Getting the mouse coordinates
mouse_x = math.floor(max_loc[0] + width / 2)
mouse_y = math.floor(max_loc[1] + height / 2)
l_param = win32api.MAKELONG(mouse_x, mouse_y)
# Trying to click on the coordinates
win32gui.PostMessage(hwnd, win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON, l_param)
win32gui.PostMessage(hwnd, win32con.WM_LBUTTONUP, 0, l_param)
print(f"Max Val: {max_val} Max Loc: {max_loc}")
cv2.rectangle(scr, max_loc, (max_loc[0] + width, max_loc[1] + height), (0, 255, 255), 2)
cv2.putText(scr, f"Max Loc: {max_loc}", max_loc, cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 255), 2)
cv2.rectangle(scr, (mouse_x, mouse_y), (mouse_x, mouse_y), (255, 255, 255), 10)
I'm trying to automate a process in BlueStacks where I wait for an element to appear on the screen, and when it appears, click it. Everything works, except the clicking part, I've done a lot of research and tried different things, but I can't get it to work.
I know I can make this easily with pyautogui, but I don't want to make the program move the actual cursor, and one of the key features is that it can be run without needing to have the window on the foreground (not focusing the window).
def compare_images():
threshold = 0.80
i = -1
width = 0
height = 0
mouse_x = 0
mouse_y = 0
for template in templates:
i += 1
result_image = cv2.matchTemplate(scr, template, cv2.TM_CCOEFF_NORMED)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result_image)
width = templates[i].shape[1]
height = templates[i].shape[0]
if max_val > threshold:
# Getting the mouse coordinates
mouse_x = math.floor(max_loc[0] + width / 2)
mouse_y = math.floor(max_loc[1] + height / 2)
l_param = win32api.MAKELONG(mouse_x, mouse_y)
# Trying to click on the coordinates
win32gui.PostMessage(hwnd, win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON, l_param)
win32gui.PostMessage(hwnd, win32con.WM_LBUTTONUP, 0, l_param)
print(f"Max Val: {max_val} Max Loc: {max_loc}")
cv2.rectangle(scr, max_loc, (max_loc[0] + width, max_loc[1] + height), (0, 255, 255), 2)
cv2.putText(scr, f"Max Loc: {max_loc}", max_loc, cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 255), 2)
cv2.rectangle(scr, (mouse_x, mouse_y), (mouse_x, mouse_y), (255, 255, 255), 10)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论