4

I have 3 USB-keyboards attached to the Linux. Normally, when writing on any one, the characters "going" to the currently active application, e.g. to terminal or any other app.

But, me reading the keyboard events from two keyboards directly by reading the particular /dev/input/eventX devices using some Perl module. While the script reads and decodes all events correctly, the entered keys are also going into the active application.

The question is: It is possible to stop routing the keyboard events from particular keyboard to the active application? E.g. somewhat tell to kernel that inputs from a particular keyboard should not be taken as normal keyboard input.

Because the X11 reads from every device which has device nodes in the /dev/input/event* it kooks like there are two possible solutions:

  1. Somewhat change the name of the USB "keyboard" to another name instead of eventN, for example /dev/input/myinput0. Unfortunately, the udev rules doesn't allows renaming the device. (The NAME directive in the rules.d works only for network devices, for other devices could create only symlink)

  2. Somewhat change the X11 configuration, in the /usr/share/X11/xorg.conf.d/10-evdev.conf, to ignore some particular "keyboard-like" devices - e.g. don't read every eventN device. Currently in my system it contains:

Section "InputClass"
        Identifier "evdev keyboard catchall"
        MatchIsKeyboard "on"
        MatchDevicePath "/dev/input/event*"
        Driver "evdev"
EndSection

Do you have any idea how to do any of the above?

The real background: I have attached two USB-RFID readers. They act as keyboards, e.g. when I touching the reader with the RFID-tag, it sends the RFID-number exactly as they was typed on the keyboard, e.g the readers act like a normal keyboard.

My application could read the RFID events (in the background), and (of course) I don't want get the characters from RFID into the active window.

2 Answers 2

2

If you are reading from /dev/input/eventX anyway, just do an EVIOCGRAB ioctl on it. You can issue ioctl's in Perl easily. Don't forget to release the grab when your program quits.

The grab will prevent all other devices, including X, from reading events from this device.

That's cleaner than xinput, because you also exclude other applications that may want to read directly from the device, and you also can control the duration of the exclusion (as long as your application runs).

1
1

You can disable input devices under X with the xinput command. Run xinput list to list available devices then xinput disable … to disable a device by name or number.

Udev is probably the way to go, but X11 is the way I know off the top of my head.

1
  • Sometimes getting a feeling that me alway trying solve things in more complicated way as it needed. This answer solves the problem easily. the xinput --disable device_id does the right thing. :) Thank you very much.
    – clt60
    Commented Jun 17, 2017 at 4:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .