有没有一种方法可以将点击事件发送到python后台的窗口中?

编程入门 行业动态 更新时间:2024-10-08 08:29:50
本文介绍了有没有一种方法可以将点击事件发送到python后台的窗口中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

因此,我正在尝试构建一个机器人,以自动化通过Bluestacks在PC上运行的手机游戏中的某些动作.

So I'm trying to build a bot to automate some actions in a mobile game that I'm running on my pc through Bluestacks.

我的程序获取窗口的屏幕快照,在图像中查找某些按钮模板并返回其坐标.

My program takes a screenshot of the window, looks for certain button templates in the image and returns their coordinates.

我现在希望能够在这些坐标处将click事件发送到窗口,但是由于我也想在机器人在后台运行时执行其他操作,因此我正在寻找一种发送鼠标的方法事件直接传递到窗口(即使已最小化/在后台),而不会影响我做其他事情或将窗口置于前景/使窗口最小化时的鼠标移动.这可能吗?

I would now like to be able to send a click event to the window at those coordinates, but since I would also like to do other things while the bot runs in the background I'm looking for a way to send the mouse event directly to the window (even if it's minimized/in the background), without influencing the movement of the mouse while I'm doing other stuff or bringing the window to the foreground/unminimizing it. Is this possible?

推荐答案

基于Dmitry的回答. x 和 y 必须是相对于Bluestacks窗口而不是屏幕的坐标.

Based on Dmitry's answer. The x and y must be the coordinates relative to the Bluestacks window not the screen.

def click(x, y): hWnd = win32gui.FindWindow(None, "BlueStacks") lParam = win32api.MAKELONG(x, y) hWnd1= win32gui.FindWindowEx(hWnd, None, None, None) win32gui.SendMessage(hWnd1, win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON, lParam) win32gui.SendMessage(hWnd1, win32con.WM_LBUTTONUP, None, lParam) click(100,100)

更多推荐

有没有一种方法可以将点击事件发送到python后台的窗口中?

本文发布于:2023-11-25 21:04:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1631341.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:发送到   后台   事件   方法   窗口中

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!