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