Skip to content. | Skip to navigation

Personal tools
Log in
Sections
You are here: Home Projects Libsuinput

Libsuinput

Helper functions to simplify Uinput usage.

Uinput allows attaching user-space device drivers into the Linux kernel. As magnificient as Uinput is, it is pretty low level from the application developers perspective. Libsuinput provides a set of helper functions and hides many devilish details.

Usage example

Create and use a new uinput device with key-capabilities:

int uinput_fd;
int keys[] = {KEY_E, KEY_H, KEY_L, KEY_O};
struct uinput_user_dev user_dev;

memset(&user_dev, 0, sizeof(struct uinput_user_dev));
strcpy(user_dev.name, "libsuinput-example-keyboard");

uinput_fd = suinput_open();

suinput_set_capabilities(uinput_fd, EV_KEY, keys, 4);

suinput_create(uinput_fd, &user_dev);

suinput_write(uinput_fd, EV_KEY, KEY_H, 1); /* Press. */
suinput_syn(uinput_fd); /* "Flushes" events written so far. */

suinput_write(uinput_fd, EV_KEY, KEY_H, 0); /* Release */
suinput_syn(uinput_fd);

suinput_write(uinput_fd, EV_KEY, KEY_E, 1);
suinput_syn(uinput_fd);

suinput_write(uinput_fd, EV_KEY, KEY_E, 0);
suinput_syn(uinput_fd);

suinput_write(uinput_fd, EV_KEY, KEY_L, 1);
suinput_syn(uinput_fd);

suinput_write(uinput_fd, EV_KEY, KEY_L, 0);
suinput_syn(uinput_fd);

suinput_write(uinput_fd, EV_KEY, KEY_L, 1);
suinput_syn(uinput_fd);

suinput_write(uinput_fd, EV_KEY, KEY_L, 0);
suinput_syn(uinput_fd);

suinput_write(uinput_fd, EV_KEY, KEY_O, 1);
suinput_syn(uinput_fd);

suinput_write(uinput_fd, EV_KEY, KEY_O, 0);
suinput_syn(uinput_fd);

suinput_destroy(uinput_fd);

Note

Error handling is omitted to keep code as readible as possible.

Download & Install

There are two ways to obtain and install libsuinput, depending on your needs.

Ubuntu 10.04 Lucid Lynx and later

Install from Codegrove's PPA:

sudo add-apt-repository ppa:tuos/codegrove
sudo apt-get update
sudo apt-get install libsuinput-dev

Other systems

Grab the latest source release and install it manually. Please refer to README and/or INSTALL files in the root of the source package for installation requirements and procedure.

Facts
Author: Tuomas Räsänen
License: GPLv3+
Programming languages: C
Source control: Bazaar
Bug control: Launchpad
Support: Launchpad