Hardware Reference
In-Depth Information
Working with Header Files
The header files required for the
uinput
API include the following:
#include <sys/ioctl.h>
#include <linux/input.h>
#include <linux/uinput.h>
To compile code, making use of I2C, you also need to install the
libi2c
development
library, if you have not done that already:
$ sudo apt-get install libi2c-dev
Opening the Device Node
The connection to the
uinput
device driver is made by opening the device node:
/dev/uinput
The following is an example of the required
open(2)
call:
int fd;
fd = open("/dev/uinput",O_WRONLY|O_NONBLOCK);
if ( fd < 0 ) {
perror("Opening /dev/uinput");
...
Configuring Events
In order to inject events, the driver must be configured to accept them. Each call to
ioctl(2)
in the following code enables one class of events based on the argument
event
.
The following is a generalized example:
int rc;
unsigned long event = EV_KEY;
rc = ioctl(fd,UI_SET_EVBIT,event);
assert(!rc);
The list of
UI_SET_EVBIT
event types is provided in Table
3-5
. The most commonly
needed event types are
EV_SYN
,
EV_KEY
, and
EV_REL
(or
EV_ABS
).