I would like my python script to listen only to the QR Code Reader which is detected as keyboard. I don't want the keyboard to write to the console or somewhere. Only the python script should listen to that keyboard on Linux. Is that possible? Is there a library or udev rules can prevent such thing?
while True:
qr_code = input()
logging.info(qr_code)
I also tried python-evdev. Where I can bind only to the device with dev.grab_context():
. It works and receive the single key events, but I don't have the mappings. So input()
is the easiest way for me.
qr_device_path = None
qr_device_name = "SM SM-2D PRODUCT HID KBW"
qr_device_phys = None
devices = [evdev.InputDevice(path) for path in evdev.list_devices()]
# QR Code Reader name: SM SM-2D PRODUCT HID KBW
for device in devices:
print(device.path, device.name, device.phys)
if(device.name == "SM SM-2D PRODUCT HID KBW"):
logging.info("found qr code reader")
qr_device_path = device.path
qr_device_phys = device.phys
if(qr_device_path):
dev = InputDevice(qr_device_path)
while True:
for event in dev.read_loop():
if event.type == ecodes.EV_KEY:
print(categorize(event))