如何在不干扰Python实际鼠标的情况下模拟鼠标单击 [英] How to simulate a mouse click without interfering with actual mouse in Python

查看:766
本文介绍了如何在不干扰Python实际鼠标的情况下模拟鼠标单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个简单的单击bot,可以在Windows PC上自动玩一个android游戏.当前,它可以确定屏幕上某些内容何时发生更改,然后移动鼠标并单击正确的按钮.

I've made a simple click bot to automatically play an android game on my Windows PC. It currently identifies when certain things change on the screen then moves the mouse and clicks the correct button.

当前,我正在使用以下win32api函数来实现此目的:

Currently I am using the following win32api functions to achieve this:

Win32api.SetCursorPos(Position)
Win32api.mouse_event(winn32con.MOUSEEVENTF_LEFTDOWN,0,0)
Win32api.mouse_event(winn32con.MOUSEEVENTF_LEFTUP,0,0)

这些工作很好,但是当我使用机器人时,它会接管计算机的鼠标,并且基本上我必须让它运行.无论如何,我是否可以实际上使用鼠标来模拟点击而没有点击,或者是否可以在其他屏幕上隔离该机器人并在另一个屏幕上自由工作呢?

These work great however when I use the bot it takes over my computer's mouse and I basically have to let it run. Is there anyway I could simulate a click without it actually using my mouse, or is there a way I could isolate the bot on one of my other screens and be able to work freely on the other?

推荐答案

有一个专门用于处理用户交互组件和periferics的库:pyautogui

There is a lib specific for deal with user interaction components and periferics: pyautogui

此处是简短易懂的文档,用于执行/模拟鼠标单击DOWN&上

Here, is a short and easy to try documentation for performing/simulating mouse click DOWN & UP

https://pyautogui.readthedocs. org/en/latest/mouse.html#the-mousedown-and-mouseup-functions

这篇关于如何在不干扰Python实际鼠标的情况下模拟鼠标单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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