运行此代码
import pyautogui
import time
#----------------------------------------------------
def mouse_scroll_1(value= 100):
pyautogui.vscroll(clicks=value)
return
#----------------------------------------------------
def mouse_scroll_2(value= 100):
try:
pyautogui.vscroll(clicks=value)
except:
try:
pyautogui.vscroll(clicks=value)
except:
pass
#----------------------------------------------------
if __name__ == '__main__':
input('Focus on a windows (faster then 3 sec) and wait, we will focus down')
time.sleep(3)
mouse_scroll_1(-100)
我收到以下错误。:
Traceback (most recent call last):
File "test2.py", line 22, in <module>
mouse_scroll_1(-100)
File "test2.py", line 6, in mouse_scroll_1
pyautogui.vscroll(clicks=value)
File "C:\Python35\lib\site-packages\pyautogui\__init__.py", line 582, in vscroll
platformModule._vscroll(clicks, x, y)
File "C:\Python35\lib\site-packages\pyautogui\_pyautogui_win.py", line 545, in _vscroll
return _scroll(clicks, x, y)
File "C:\Python35\lib\site-packages\pyautogui\_pyautogui_win.py", line 514, in _scroll
_sendMouseEvent(MOUSEEVENTF_WHEEL, x, y, dwData=clicks)
File "C:\Python35\lib\site-packages\pyautogui\_pyautogui_win.py", line 480, in _sendMouseEvent
raise ctypes.WinError()
PermissionError: [WinError 5] Access denied.
我可以通过运行函数来修复错误:mouse_scroll_2()
有人可以解释一下可能出现错误的原因吗?
答案 0 :(得分:0)
最后我明白了:
import win32api
import win32con
def mouse_scroll_3(value= 100):
win32api.mouse_event(win32con.MOUSEEVENTF_WHEEL, 0, 0 , value, 0)
return
然而没有回答为什么它与pyautogui失败: - (