Trovo device dinamicamente
parent
78e0426f7c
commit
dc60a62063
|
|
@ -4,10 +4,16 @@ Created on 1 ott 2019
|
|||
@author: Emanuele Trabattoni
|
||||
'''
|
||||
|
||||
from evdev import InputDevice, ecodes, categorize
|
||||
from evdev import InputDevice, ecodes, categorize, list_devices
|
||||
from select import select
|
||||
|
||||
dev = InputDevice('/dev/input/by-id/usb-0581_0106-event-kbd')
|
||||
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()
|
||||
|
||||
|
|
@ -24,22 +30,28 @@ char_map = {
|
|||
458791: 0,
|
||||
458792: "Invio"
|
||||
}
|
||||
|
||||
|
||||
def get_numero(dev):
|
||||
stringa = ""
|
||||
last = None
|
||||
while True:
|
||||
r,w,x = select([dev], [], [])
|
||||
r, w, x = select([dev], [], [])
|
||||
for event in dev.read():
|
||||
if event.code == 4 and event.type==4:
|
||||
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(x[0:12])
|
||||
print("ricevo", x[0:12])
|
||||
|
|
|
|||
Loading…
Reference in New Issue