[英]Why does the following mouse click code results in Windows error 997?
I am doing a mini project where a switch press results in a mouse click or in other words the switch acts as an alternative to my left mouse button. 我正在做一个迷你项目,其中按下开关会导致鼠标单击,或者换句话说,开关会替代我的鼠标左键。
My code is 我的代码是
import pyautogui , time , serial
port = serial.Serial('COM3',9600)
flag=0
while 1:
reading=port.read()
x=ord(reading)
if x==1 and flag==0:
flag=1
pyautogui.mouseDown()
elif x==2:
flag=0
pyautogui.mouseUp()
The serial transmission is such that it receives a 串行传输可以接收
0 - Switch not pressed
0-未按下开关
1 - Switch pressed1-按下开关
2 - switch just left2-向左切换
A 2 is always transmitted in between a 1 and a 0. A 2始终在1和0之间传输。
My problem is that when I run this code the following error occurs after one mouse click. 我的问题是,当我运行此代码时,单击鼠标后会发生以下错误。
Traceback (most recent call last):
追溯(最近一次通话):
File "C:\\Python27\\LeftClick.py", line 12, in pyautogui.mouseUp()
pyautogui.mouseUp()中的文件“ C:\\ Python27 \\ LeftClick.py”,第12行
File "C:\\Python27\\lib\\site-packages\\pyautogui__init__.py", line 234, in mouseUp
在mouseUp中的文件“ C:\\ Python27 \\ lib \\ site-packages \\ pyautogui__init __。py”,第234行
platformModule._mouseUp(x, y, 'left')
platformModule._mouseUp(x,y,'left')
File "C:\\Python27\\lib\\site-packages\\pyautogui_pyautogui_win.py", line 415, in _mouseUp
_mouseUp中的文件“ C:\\ Python27 \\ lib \\ site-packages \\ pyautogui_pyautogui_win.py”,行415
_sendMouseEvent(MOUSEEVENTF_LEFTUP, x, y)
_sendMouseEvent(MOUSEEVENTF_LEFTUP,x,y)
File "C:\\Python27\\lib\\site-packages\\pyautogui_pyautogui_win.py", line 480, in _sendMouseEvent raise ctypes.WinError()
_sendMouseEvent中的文件“ C:\\ Python27 \\ lib \\ site-packages \\ pyautogui_pyautogui_win.py”,行480引发ctypes.WinError()
WindowsError: [Error 997] Overlapped I/O operation is in progress.
WindowsError:[错误997]重叠的I / O操作正在进行中。
In the comments above, you say that if you take serial out, the program works as expected, if I read it correctly. 在上面的评论中,您说,如果您取出串口,则如果我正确阅读该程序,它将按预期工作。 You also say that mouse movement works OK on COM3, but if removing the serial comms fixes the issue, then I'd say that's a fairly strong indication that COM3 may be the culprit, it should certainly be investigated.
您还说鼠标移动在COM3上可以正常工作,但是如果删除串行通信可以解决此问题,那么我想说这是一个很强的迹象,表明COM3可能是罪魁祸首,应该进行调查。
My suggestion: Use a different COM port for your serial device. 我的建议:为串行设备使用其他COM端口。 You can change the number used by going into:
您可以通过以下方法更改使用的号码:
Device Manager > Ports (COM & LPT) > Right Click your device > Properties > Port Settings > Advanced > COM Port Number
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.