Mouse Click without moving Cursor [Python]

╄→尐↘猪︶ㄣ 提交于 2019-12-14 04:02:00

问题


I can't seem to find a specific answer to this question. How do I click coordinates on the screen without moving the cursor? I am working on a project that will automate installations of programs, but would still like control of the mouse to do other tasks while installations are being processed. Any ideas? Some examples would be awesome as well. Thanks


回答1:


Thank you to those who have tried to help me out. After further research I have found a solution. I have found a way to import AutoIt into Python by using PyAutoIt. There is a ControlClick function that I have been looking for that clicks a control without moving the mouse cursor. Here is an example:

import autoit
import time

autoit.run("notepad.exe")
autoit.win_wait_active("[CLASS:Notepad]", 3)
autoit.control_send("[CLASS:Notepad]", "Edit1", "hello world{!}")
time.sleep(5)
autoit.win_close("[CLASS:Notepad]")
autoit.control_click("[Class:#32770]", "Button2")

Thanks again. This thread can be marked answered and closed :)




回答2:


If you know the screen coordinates you want to click, you could try:

import pyautogui
x, y = 500, 250 # or whatever
pyautogui.click(x, y)

This will move to mouse pointer to (x, y) and do a left mouse click.



来源:https://stackoverflow.com/questions/34012543/mouse-click-without-moving-cursor-python

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