Using uinput driver in Linux-2.6.x 1. Introduction The linux 2.6.x provides a driver called "uinput" driver, which helps the users to inject the data to the linux. This is very useful while writing the applications to interface the customized input devices like wireless joystick, keyboard, etc. This driver uses the /dev/uinput device called user injection device, to pump the customized input device data. 2. How to use "uinput" driver 2.1 Loading "uinput" driver Load the uinput driver module using the "modprobe uinput" in the linux command prompt. This will create the device node "/dev/uinput", and further transcation will be using this node. 2.2 Opening the uinput device All the data coming from input device is given to the linux using the "/dev/uinput" device node. The user program should open the /dev/uinput device to use it further. Since the linux treats the device as a file the open() function can be used to open the file. The fopen() function return a handler for the device. example: open("/dev/uinput",O_WRONLY | O_NDELAY); if (out_fd < 0) { printf("\r\nNo uinput driver loaded! \r\n"); } After opening the device the program should set the input device parameters(keyboard event, mouse event, etc) using the ioctl() function. The following example is given for keyboard parameters: example: ioctl (out_fd, UI_SET_EVBIT, EV_KEY); ioctl (out_fd, UI_SET_EVBIT, EV_REP); The EV_KEY and EV_REP informs the uinput driver as the event is keyboard event and the key value contains the key repetation property. 2.3 Pumping the event to uinput device All the events coming from the user program will be carried to the kernel space through the structure "struct input_event" defined in kernels "input.h" A the keyboard event can be generated using the following piece of code: struct input_event event; event.type = EV_KEY; //indicates the keyboard event event.code = KEY_A; //Key value event.value = 0; //amount of key write (out_fd, &event, sizeof event); The above piece of code is used to generate the keyboard event and the key value of character 'a'. This pumps the key 'a' to the input driver(kernel space) and prints the data on the console(or any editor incase the editor is opened!). This way giving data to the input driver is similar to the normal keyboard key press. In this way, any input event can be generated using a program, which means any customized input device can be interfaced with the linux. Author: Mohan