This project contains a simple virtual keyboard implementation for Linux, utilizing the uinput and input subsystems. It reads input events from a specified input device and can emit customized events using a callback mechanism.
- Linux operating system
- g++ compiler
- Linux kernel headers (for uinput)
- Install the necessary packages:
sudo apt-get update
sudo apt-get install build-essential linux-headers-$(uname -r)
-
Clone the repository or download the source files to your local machine.
-
Navigate to the directory containing the source files.
-
Compile the program using
make
:
make
-
Ensure you have read permissions to the input event file and write permissions to
/dev/uinput
. You may need to run the program as root or adjust permissions accordingly. -
Run the executable with:
# example
sudo ./MyVirtualKeyboard /dev/input/event3
The program can be customized by modifying the callback function in the main
function. The example provided changes the KEY_A
event to a KEY_S
event:
keyboard.run([&keyboard](const input_event &ie) {
if (ie.type == EV_KEY)
{
keyboard.emit(ie.type, ie.code == KEY_A ? KEY_S : ie.code, ie.value);
}
else
{
keyboard.emit(ie.type, ie.code, ie.value);
}
});
You can modify this logic to implement your own event handling rules.
To remove the compiled files, run:
make clean
If your keyboard has an integrated touchpad, using EVIOCGRAB to grab the keyboard input device may cause the touchpad to stop functioning. This is because EVIOCGRAB captures all input events from the device, preventing other processes from receiving touchpad events. In such cases, you may need to find a balance between using EVIOCGRAB and maintaining touchpad functionality or consider alternate methods of handling input events.
https://docs.kernel.org/input/event-codes.html
This project is licensed under the MIT License.
This software is provided "as-is" without any warranties. The author is not responsible for any damage caused by using this software. Use at your own risk.