1) How to configure X to ignore the keyboard
Use lsusb
to find the ID of your barcode scanner (in format 0123:4567
). Create or modify an xorg.conf
file (usually in /etc/X11/
). Add a InputClass
section with the ID you just found:
Section "InputClass"
Identifier "barcode"
MatchUSBID "0123:4567"
Option "Ignore" "true"
EndSection
Restart X, verify in Xorg.log
that your device is recognized by this section and ignored.
2) The conversion from keypresses to ASCII (or other) codes is pretty involved, to allow for different keyboard layouts, dead keys, customizations etc. Now that you disabled the X conversion layer, you can receive keypress and keyrelease events from the appropriate /dev/input/eventX
device. The number can change; for your barcode reader, there will be a symlink in /dev/input/by-id/
which doesn't change. So use the symlink.
You can run evtest
on this file to see what kind of events it generates. They mapping for your barcode reader will be simple, so a table lookup from keysym to ASCII code will do. You can process these events in your own program, see the evtest
source, or e.g. here. You can also write a small C program which just reads this device and produces ASCII on stdout, and then integrate it into your application using a pipe etc.
"Mapping it as an ASCII stream device" is not possible, such devices don't exist in the Linux kernel.
3) Setting permissions
You need to write a custom udev
rule to set permissions for your input device. SUBSYSTEM
must match input
, ACTION
must match ADD
, the environment ENV
should contain information to match the device (use udevadm
to find out details), and you can set OWNER
, GROUP
and MODE
for the newly created /dev/input/eventX
device. Here's a somewhat general howto , I couldn't find a more specific one. Google for better tutorials.