Funziona ma crasha con altri device
This commit is contained in:
+36
-5
@@ -3,12 +3,43 @@ Created on 1 ott 2019
|
||||
|
||||
@author: Emanuele Trabattoni
|
||||
'''
|
||||
from evdev import InputDevice
|
||||
|
||||
from evdev import InputDevice, ecodes, categorize
|
||||
from select import select
|
||||
|
||||
dev = InputDevice('/dev/input/by-id/usb-0581_0106-event-kbd')
|
||||
#dev = InputDevice('/dev/input/by-id/usb-Chicony_USB_Keyboard-event-kbd')
|
||||
dev.grab()
|
||||
while True:
|
||||
r,w,x = select([dev], [], [])
|
||||
for event in dev.read():
|
||||
print(event)
|
||||
|
||||
char_map = {
|
||||
458782: 1,
|
||||
458783: 2,
|
||||
458784: 3,
|
||||
458785: 4,
|
||||
458786: 5,
|
||||
458787: 6,
|
||||
458788: 7,
|
||||
458789: 8,
|
||||
458790: 9,
|
||||
458791: 0,
|
||||
458792: "Invio"
|
||||
}
|
||||
def get_numero(dev):
|
||||
stringa = ""
|
||||
last = None
|
||||
while True:
|
||||
r,w,x = select([dev], [], [])
|
||||
for event in dev.read():
|
||||
if event.code == 4 and event.type==4:
|
||||
if last is None:
|
||||
last = char_map[event.value]
|
||||
if last != "Invio":
|
||||
stringa += str(last)
|
||||
else:
|
||||
yield stringa
|
||||
stringa = ""
|
||||
else:
|
||||
last = None
|
||||
|
||||
for x in get_numero(dev):
|
||||
print(x[0:12])
|
||||
Reference in New Issue
Block a user