我有一個下面的代碼,我用它來捕捉來自條形碼掃描器的輸入。問題是,我要保存在數據庫全掃描碼,但對新行代碼打印每一個字符:Python evdev和條形碼掃描器
#!/usr/bin/env python
from evdev import InputDevice, ecodes, list_devices
from select import select
keys = "X^1234567890XXXXqwertzuiopXXXXasdfghjklXXXXXyxcvbnmXXXXXXXXXXXXXXXXXXXXXXX"
dev = InputDevice("/dev/input/event10")
barcode = ""
while True:
r,w,x = select([dev], [], [])
for event in dev.read():
if event.type == 1 and event.value == 1:
barcode += (keys[event.code])
print barcode
# sudo ./bar-code-test.py
#0
#00
#00
#000
#001
#1001
#0017
#70017
#00170
#000170
#001708
#8001708
#0017085
#50017085
#00170853
#300170853
#001708531
#1001708531
#0017085316
#60017085316
#00170853160
#000170853160
#001708531601
#1001708531601
#0017085316013
#30017085316013
#00170853160131
#100170853160131
#00170853160131X
#00170853160131X
我與蟒蛇新手,所以任何幫助將不勝感激。
代碼從不打印。無論如何,我發現了這個問題。 – bosha