45 lines
1.0 KiB
Python
45 lines
1.0 KiB
Python
'''
|
|
Created on 1 ott 2019
|
|
|
|
@author: Emanuele Trabattoni
|
|
'''
|
|
|
|
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()
|
|
|
|
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]) |