Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am looking forward to buy a barcode scanner for a project. This project is a web application running as a web server on the local computer, and a browser on that same machine for the client-side. The barcode scanner would be attached to that machine.

It seems a lot USB barcode scanners emulate a keyboard, however I would like to differentiate regular keyboard input from the barcode scanner data. How could I achieve that ?

Getting the barcode data on the server-side

An interesting configuration for me would be to simply fetch the data from the barcode scanner from my application (I think this can be done by reading from /dev/input/by-path/pci-XXX-usb-XXX-kbd), and disable that device in Xorg (since the /etc/X11/Xorg.conf file is mostly bypassed in recent ubuntu versions, I don't know how to do that).

Note that I would like if possible to trap input from the barcode scanner while my application doesn't have focus (it's the server part of a web application, so it's not even an Xorg application), so I do need to prevent Xorg from sending the events to the focused application.

Getting the barcode data on the client-side

Otherwise, I could map a fake keyboard layout on the barcode scanner (eg. mapping the digits to obscure utf-8 characters) but keep the regular layout for the keyboard, using this technique detailed on Super User . Then I would know when the barcode scanner is used because I would recieve weird digits on the client side (a web page).

share|improve this question
Relevant question on SO: Accessing multiple keyboards input by C++ (or python) in linux – gertvdijk Feb 1 '13 at 22:52
@gertvdijk Indeed, thanks, I think I saw that one during my research, but didn't focus on it because it doesn't give a solution for preventing Xorg from also getting the scancodes, although that other question on askubuntu gives a solution for that. I'm however curious if there's a better method to achieve what I want. – Georges Dupéron Feb 1 '13 at 23:02
I believe this is going to be quite hard. I see only ways to grab "the keyboard", but in practice it's grabbing "the keyboard on the current display", i.e. all events from all keyboards together. Will be very much interested about the outcome of this question. I would like to use this for a Yubikey implementation on a web application. – gertvdijk Feb 1 '13 at 23:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.