-2

I've been trying to get string outputs from using a barcode scanner with evdev in python. This was my script...

from evdev import *
dev = InputDevice('/dev/input/event2')

print(dev)

for event in dev.read_loop():
    if event.type == ecodes.EV_KEY:
        print(categorize(event))

And when I scan after this, I get this output:

key event at 1526024323.229556, 5 (KEY_4), down
key event at 1526024323.237564, 5 (KEY_4), up
key event at 1526024323.245549, 11 (KEY_0), down
key event at 1526024323.253534, 11 (KEY_0), up
key event at 1526024323.261553, 2 (KEY_1), down
key event at 1526024323.269538, 2 (KEY_1), up
key event at 1526024323.277549, 10 (KEY_9), down
key event at 1526024323.285565, 10 (KEY_9), up
key event at 1526024323.293555, 2 (KEY_1), down
key event at 1526024323.301535, 2 (KEY_1), up
key event at 1526024323.309553, 7 (KEY_6), down
key event at 1526024323.317533, 7 (KEY_6), up
key event at 1526024323.325553, 10 (KEY_9), down
key event at 1526024323.333537, 10 (KEY_9), up
key event at 1526024323.341554, 3 (KEY_2), down
key event at 1526024323.349537, 3 (KEY_2), up
key event at 1526024323.357552, 2 (KEY_1), down
key event at 1526024323.365537, 2 (KEY_1), up
key event at 1526024323.373554, 2 (KEY_1), down
key event at 1526024323.381535, 2 (KEY_1), up
key event at 1526024323.389555, 3 (KEY_2), down
key event at 1526024323.397535, 3 (KEY_2), up
key event at 1526024323.405552, 4 (KEY_3), down
key event at 1526024323.413537, 4 (KEY_3), up
key event at 1526024323.421554, 10 (KEY_9), down
key event at 1526024323.429537, 10 (KEY_9), up
key event at 1526024323.437579, 28 (KEY_ENTER), down
key event at 1526024323.445533, 28 (KEY_ENTER), up

I don't understand any of it, since I'm new to python, but I don't think that would make much difference in this case. I have checked the other related questions but I could not make the answers from them work. Please help me out guys.

How do I filter out the ups and keep the downs.

1 Answers1

0

Barcode scanners often (always?) act as a keyboard. Scanning a barcode with a barcode scanner appears to the computer exactly the same as if you had a keyboard plugged in, typed the number and pressed enter.

If you have a command prompt or a text editor open and scan something, do you see the number appear as if you had typed it?

Usually you don't need to use a low level interface to interact with it - just use the built in input()

SpoonMeiser
  • 19,918
  • 8
  • 50
  • 68