libbeepz/libbeepz_test/test.py

58 lines
1.5 KiB
Python

'''
Created on 1 ott 2019
@author: Emanuele Trabattoni
'''
from evdev import InputDevice, ecodes, categorize, list_devices
from select import select
devices = [InputDevice(path) for path in list_devices()]
d = filter(lambda x: x.info.vendor == 1409
and x.info.product == 262
and ('KEY_1', 2) in x.capabilities(verbose=True)[('EV_KEY', 1)], devices)
lista = list(d)
dev = lista[0]
#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:
try:
last = char_map[event.value]
if last != "Invio":
stringa += str(last)
else:
yield stringa
stringa = ""
except KeyError:
print("Carattere sconosciuto")
else:
last = None
for x in get_numero(dev):
print("ricevo", x[0:12])