What i have:

  • Linux machine (debian stable) without monitor, keyboard, no X running
  • USB-device which acts like an USB-keyboard (like many barcode-readers [1])

What i (don't) want:

  • I want to use this device only for one specific application.
  • I don't want to have this device interfere with e.g. the login process after booting or anything else - except the one application.
  • In any way, i want to be able to plug in a plain old USB keyboard an use it as such - independent of how many other USB-devices like mentioned above may be connected or not.

What i (don't) know:

  • I found some example codes, about how to read directly from the event devices and can use this in my application, if needed.
  • I don't know, how to disable a specific keyboard for the whole system except this specific application? Is this even possible?

Thanks for any hints ... !

[1] When the device reads a barcode, it's sends the detected code as single key presses and commits with return.

  • Perhaps there is a better word instead of "bind" which reveals better search results? Any hints appreciated! – m.sr May 2 '12 at 16:49
  • 1
    I know this is an old thread, but I found the answer here: stackoverflow.com/questions/1698423 – user185406 Aug 13 '13 at 7:13
  • @McLovin ... thanks a lot, exactly what i was searching for! – m.sr Sep 21 '13 at 12:12

A challenging and interesting question!

I think udev might be capable of doing just that. Create a file /etc/udev/rules.d/99-barcode-reader.rules and put there something similar to this:

ACTIONS!="add", GOTO="barcode_end"
SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ATTRS{idVendor}=="dead", ATTRS{idProduct}=="beef", PROGRAM="/bin/sh -c 'logger -p user.info Hey, I see a new device $env{BUSNUM} $env{DEVNUM}'", RUN+="/bin/sh -c '/usr/local/bin/your_barcode_application &'"

Replace "dead" and "beef" with the values you get for idVendor and idProduct with lsusb.

Restart udevd or simply your server, and see what happens.

  • 1
    Thank you for your input. Sadly there is no way to disable a keyboard device with udev i know of. Your example udev-rule sure helps discovering the right device but doesn't help to "bind" my device to a distinct application. So the input device is still cluttering the login-prompt of the current console for example ... – m.sr May 2 '12 at 16:46

I dunno if it's what you want to do but if you're trying to disable the keyboard emulation that output barcode sequences in stdin/console just try this:

Create a file "/etc/udev/rules.d/10-barcode.rules"

SUBSYSTEM=="input", ACTION=="add", ATTRS{idVendor}=="xxxx", ATTRS{idProduct}=="yyy", RUN+="/bin/sh -c 'echo remove > /sys$env{DEVPATH}/uevent'"
ACTION=="add", ATTRS{idVendor}=="xxxx", ATTRS{idProduct}=="yyyy", SYMLINK+="barcode"

Of course, replace xxxx and yyyy with your own vendor_id and product_id, and reload the rules with "udevadm control --reload"

This will remove the event/input part that is emulating keyboard and keep the hidraw part to access barcode scans. The second line just create a /dev/barcode device to read linked to the hidraw

Just open that file in your code to read strings sent by the barcode

  • Yes it works! This should be the solution, thank you! :) But the reload thing did not do it for me, I had to reboot. – FlorianB Aug 22 '20 at 1:27
  • I made a post + answer for a very similar situation I had with a DIY keyboard, and I added a few things worth noting: stackoverflow.com/a/63531743/3105222 – FlorianB Aug 22 '20 at 6:16

For what it's worth and for anyone with a similar problem finding this;

I don't know if it's possible to disable a "keyboard", but since the system is headless anyway, you can just run a service to handle the input in TTY1, replacing the normal login prompt. You can still login normally via ssh or any other TTY, but on boot, by default, the barcode reader input is handled properly without additional action.

A nice bonus is to run all of that inside a screen session, so you can connect to it using ssh.

For instructions, check out my answer on SU here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.