Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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 want to connect two usb keypads to the same computer (Linux). Then I want to open 2 consoles #1 and #2 and execute one process on each one of them. Then I want to receive input from keypad #1 on console #1 and input from keypad #2 on console #2, that is, each keypad submits input to a specific process. How can this be achieved? Assume code is written in C. Thanks!

share|improve this question
Are these two consoles, as in /dev/tty1 and /dev/tty2? Or two terminals under X? Or do you only care to route the input to two processes, without caring whether it goes through terminals? – Gilles Nov 4 '11 at 23:25
Thanks for responding. Ideally I'd like to route the input from each keypad to given process. Each process must execute a "scanf" and receive input from one of the keypads, not both. I mentioned consoles in my example because it was easier to explain my problem this way. It wouldn't help to learn about all options though. If it's to difficult to explain here I'd be more than happy if you could point me out where I can read about this. – martincho Nov 5 '11 at 0:44
up vote 0 down vote accepted

To have a program read input from a particular keyboard, you can make it read the raw events from the right input device. The input devices are (with a typical udev setup) /dev/event[0-9]*, and you can find out which one you're after through /dev/input/by-id/*-kbd and /dev/input/by-path/*-kbd. Look in by-id to match the device by its identification (vendor and serial number), or in by-path to match it by the USB port that it's plugged into.

You may want to fine-tune the udev rules that generate the names in /dev/*/by-*/. You can find the information that udev has at its disposal by running udevadm info -a -n /dev/input/event42 (you can also tell udev to use the output from some other program, if you have a program that reports more information about a device). If you're having trouble distinguishing between the two keypads, look at the udevadm info output for distinguishing characteristics. You can also run udevadm test /class/input/event42 to see what rules udev is currently applying.

share|improve this answer

Your Answer


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

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