Python过程需要很长时间

时间:2016-05-16 05:06:55

标签: python

实际上我是从arduino导入串行数据而我正在使用python将鼠标的当前位置移动到特定的像素。我的问题是每当我的if语句为真,即使一秒钟,python执行函数(mousemove)移动鼠标超过5到10秒。我每次都得到延迟回应。我希望程序能够在读取更改时立即工作,这样我就可以顺利移动鼠标。

我的代码:

import pyautogui
import serial
irData = serial.Serial('com3',9600)
print('Press Ctrl-C to quit.')

def movemouse( int ):
print(dataint)
pyautogui.moveTo(500,500)
return;


while 1:

    while(irData.inWaiting()==0):
      pass
      data = irData.readline() #collecting data from serial port and  assigning into data varibale        

      try:
        dataint = int(data) # Return an integer value from a string
        x, y = pyautogui.position()      # Assign the mose position into varibale x and y
        positionStr = 'X: ' + str(x).rjust(4) + ' Y: ' +  str(y).rjust(4)

     #It allows the program to take same amount of space inspite of having different integer values as in unit or thousands and show it in proper x & y format. 
         if dataint >=120:
           movemouse(dataint)                         

         else:
           print(dataint)   #Print the current mouse coordinates.            
      except KeyboardInterrupt:
        print "Done"

0 个答案:

没有答案