The following package must be installed before building vinput
.
In order to compile the kernel driver successfully, package versions of currently used kernel, kernel-devel and kernel-headers need to be matched.
$ sudo apt install linux-headers-$(uname -r)
After running make
, you should be able to generate the following files:
vinput.ko
- virtual input device layervkbd.ko
- virtual keyboardvmouse.ko
- virtual mousevts.ko
- virtual multitouch screen inputs
The module can be loaded to Linux kernel by runnning the command:
$ sudo insmod vinput.ko
$ sudo insmod vkbd.ko
vinput
is a API to allow easy development of virtual input drivers.
The drivers needs to export a vinput_device
function that contains the virtual device name and vinput_ops
structure that describes:
- the init function:
init
- the input event injection function:
send
- the readback function:
read
Then using vinput_register_device
and vinput_unregister_device
will add a new device to the list of support virtual input devices.
int init(struct vinput *);
This function is passed a struct vinput already initialized with an allocated struct input_dev
.
The init
function is responsible for initializing the capabilities of the input device and register it.
int send(struct vinput *, char *, int);
This function will receive a user string to interpret and inject the event using the input_report_XXXX
or input_event
call.
The string is already copied from user.
int read(struct vinput *, char *, int);
This function is used for debugging and should fill the buffer parameter with the last event sent in the virtual input device format. The buffer will then be copied to user.
vinput
devices are created and destroyed using sysfs.
event injection is done through a /dev
node.
The device name will be used by the userland to export a new virtual input device.
To create a vinputX
sysfs entry and /dev
node.
$ echo "vkbd" | sudo tee /sys/class/vinput/export
To unexport the device, just echo its id in unexport:
$ echo "0" | sudo tee /sys/class/vinput/unexport
This is the virtual keyboard. It supports all KEY_MAX
keycodes.
The injection format is the KEY_CODE
such as defined in linux/input.h
.
A positive value means KEY_PRESS
while a negative value is a KEY_RELEASE
.
The keyboard supports repetition when the key stays pressed for too long.
Simulate a key press on "g" (KEY_G
= 34)
$ echo "+34" | sudo tee /dev/vinput0
Simulate a key release on "g" (KEY_G
= 34)
$ echo "-34" | sudo tee /dev/vinput0
vinput
is released under the GNU General Public License. Use of this source code is governed by
the GPL License version 2 that can be found in the LICENSE file.
- virtual_touchscreen: A simple evdev linux device driver and GUI program to simulate multitouch touchscreen.
- mqtt2js: Linux virtual joystick controlled by MQTT
- VirtualMouse: Virtual mouse drivers for linux.