Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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 want to create a C program that accepts input from a joypad (/dev/input/js0), processes it, and then sends it to a fake device file (character or block) labeled as a keyboard (oh, and what is the device file for a keyboard?. I would like to know if it is possible to do this, and if so, how.

share|improve this question
I think this covers the central part of your question: How to inject keystrokes via a shell script? – Gilles Jul 6 '12 at 1:39
Do you actually want to send data to the keyboard or do you want data to look like it came from a keyboard? For the later there already is a kernel driver called uinput. I have never used it as a programmer, but you can start here thiemonge.org/getting-started-with-uinput – Bananguin Jul 6 '12 at 6:51
@user1129682: What do you mean by sending data to the keyboard? Do you mean injecting keystrokes on a TTY level? And as for what I want to do, I would like to know how to send characters on as low a level as possible, but X.org (GUI) stuff will do fine. Oh, and I believe that you mean 'latter', not 'later'. – InkBlend Jul 7 '12 at 3:09
With data to the keyboard I mean data/bits being sent from your kernel to the actual device with the many keys and some leds. :-) So you are trying to get data to X. In that case uinput is exactly what you are looking for. Look for the toolchain to connect a wiimote to X. They use uinput to send keystrokes to X. – Bananguin Jul 7 '12 at 7:05
up vote 2 down vote accepted

Look closely at an excerpt from an ls -al /dev command on my system:

brw-rw----  1 root floppy    8,   0 Jun  7 19:55 sda
brw-rw----  1 root floppy    8,   1 Jun  7 19:55 sda1
brw-rw----  1 root floppy    8,   2 Jun  7 19:55 sda2
brw-rw----  1 root floppy    8,   3 Jun  7 19:55 sda3
brw-rw----  1 root floppy    8,   5 Jun  7 19:56 sda5
brw-rw----  1 root floppy    8,   6 Jun  7 19:56 sda6
brw-rw----  1 root floppy    8,   7 Jun  7 19:56 sda7
brw-rw----  1 root floppy    8,   8 Jun  7 19:57 sda8
brw-rw----  1 root floppy    8,  16 Jun  7 19:55 sdb
brw-rw----  1 root floppy    8,  32 Jun  7 19:55 sdc
brw-rw----  1 root floppy    8,  33 Jun  7 19:55 sdc1
brw-rw----  1 root floppy    8,  34 Jun 11 10:39 sdc2
brw-rw----  1 root floppy    8,  35 Jun  7 19:56 sdc3

The two numbers after the group ID but before the date are the device file's major and minor numbers. This is basically the "kind" of device it is. 8 in this case is a SCSI (or emulated SCSI) disk drive.

http://lxr.linux.no/linux/Documentation/devices.txt is a somewhat not-so-recent list of all the major and minor numbers. Not sure of the official location of the latest version of the list.

So anyway, these files are created with the mknod command (mknod [OPTION]... NAME TYPE [MAJOR MINOR], some types are b for block, c for character). There's also a mknod() system call. I don't fully know the implications if you create another file with the same major/minor as an existing device.

uinput as described in the comments is probably what you are looking for, although on PC hardware there is a /dev/psaux that reads/writes directly to the PS/2 port if your system is old enough to have one. Could not even tell you where to begin with USB keyboards ...

If you just want a fake device file and don't care what happens to the data you send to it, there's always /dev/zero. Also symlinks may be a real simple solution in that case.

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.