你可能需要安装的python库:
pip install pyautogui
使用下面的代码
import time
from ctypes import *
import pyautogui
pyautogui.FAILSAFE = False # 加这行就可以解决
time.sleep(5)
i = 0
while 1:
# windll.user32.SetCursorPos(600,300);
# windll.user32.SetCursorPos(900,300);
if i % 2 == 0:
pyautogui.click(1500, 600, clicks=1, interval=0.0, button='left')
else:
pyautogui.click(1600, 700, clicks=1, interval=0.0, button='left')
time.sleep(6)
print("==================this is the : " + str(i)+" times click=================")
—
不加pyautogui.FAILSAFE = False
的话,会报错(类似下面这样的):
Traceback (most recent call last):
File "c:/Users/qapd04/Desktop/fr_project/自动点击屏幕,防止屏幕休眠.py", line 11, in <module>
pyautogui.click(1500, 600, clicks=1, interval=0.0, button='left')
File "D:\Program Files\Python38\lib\site-packages\pyautogui\__init__.py", line 597, in wrapper
failSafeCheck()
File "D:\Program Files\Python38\lib\site-packages\pyautogui\__init__.py", line 1722, in failSafeCheck
raise FailSafeException(
pyautogui.FailSafeException: PyAutoGUI fail-safe triggered from mouse moving to a corner of the screen. To disable this fail-safe, set pyautogui.FAILSAFE to False. DISABLING FAIL-SAFE IS NOT RECOMMENDED.
—
参考链接:
https://blog.csdn.net/weixin_41267342/article/details/104313265?spm=1001.2014.3001.5506
https://www.kkwen.cn/index.php/archives/24/
https://blog.csdn.net/u013797426/article/details/127079573
—
—
发表回复