I have written this code where I process scanned input from barcode scanner. But input here are from single line and I can't get difference between the next scanned input and the past one. Here is my code:
from evdev import InputDevice, categorize, ecodes
import select
dev = InputDevice('/dev/input/event2')
data = ""
def parse_key_to_char(val):
return CODE_MAP_CHAR[val] if val in CODE_MAP_CHAR else ""
for event in dev.read_loop():
if event.type == ecodes.EV_KEY:
e = categorize(event)
if e.keystate == e.key_up:
print parse_key_to_char(e.keycode)
And the Output is:
0
7
5
6
7
8
1
6
4
1
2
5
While expected output is :
075678164125
It works if I am in the same terminal but won't work if I am focusing on some other terminal. I want these inputs to be captured in the background and pass them to some other function which is calling current function.