0
我正在使用這裏的一些代碼從我的linux筆記本電腦上的usb鼠標獲取x,y三角洲。這是一個腳本,可以獲取deltas並用matplotlib繪製它。但主要問題是,我不能停止測量而不殺死整個腳本。我在編程方面仍然是初學者,所以任何幫助都會很好。如何在不停止整個腳本的情況下停止數據測量
我的代碼:
import struct
import matplotlib.pyplot as plt
import numpy as np
import time
from drawnow import *
file = open("/dev/input/mouse2", "rb");
test = []
plt.ion()
def makeFig():
plt.plot(test)
#plt.show()
def getMouseEvent():
buf = file.read(3);
button = ord(buf[0]);
bLeft = button & 0x1;
x,y = struct.unpack("bb", buf[1:])
print ("x: %d, y: %d\n" % (x, y))
return x,y
while True:
test.append(getMouseEvent())
drawnow(makeFig)
file.close();
你只想鼠標數據的追加切換到'test',或做你想擺脫'while'循環嗎? –