How to simulate a mouse click without interfering with actual mouse in Python

☆樱花仙子☆ 提交于 2020-01-17 05:07:13

问题


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.

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?


回答1:


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

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



来源:https://stackoverflow.com/questions/33319485/how-to-simulate-a-mouse-click-without-interfering-with-actual-mouse-in-python

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