Transforming a Keyboard to a Mouse in Software

Transforming a Keyboard to a Mouse in Software

You’ve probably heard the old saying that if it looks like a duck, and it quacks like a duck… So when is a keyboard a mouse? When software makes it quack like a mouse — that is, if mice quacked. [Blackle Mori] took a cheap USB keypad and, using the libevdev Linux system, made it impersonate a mouse.


The code on GitHub isn’t complex, but the details can take some time to get right. The code takes over all input events from the device. [Blackle] dumped out events sent from the keypad, but the stock evtest program would probably have done just as well.



Armed with the knowledge of what events belong to what keys, it is simple to replace them with messages that generally come from a mouse. This involves creating a virtual device that takes a surprisingly large number of lines of code, but none are particularly difficult to understand.


There are a few neat tricks that aren’t directly related. For example, [Blackle] wanted to have some keys launch programs. However, grabbing ownership of the keyboard requires you to run as root. You don’t want to launch your browser as root. Not only is it unsafe, but you’ll have the wrong configuration files. Luckily, Linux capabilities let it work the way you would like.


Overall, it is a neat approachable example of a technique you could use for many things. It isn’t hard to imagine a microcontroller on a serial port feeding mouse and keyboard events to the computer using a scheme like this. Sure, if you have the right USB micro, you could emulat ..

Support the originator by clicking the read the rest link below.