Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to intercept keyboard input at the lowest level in linux?

I am interested in writing a program for linux that will read ALL keystrokes, process it and THEN output to the rest of the running processes. Essentially, ALL keyboard input must go into this program and this program alone...Then the program will act as the keyboard for the rest of the computer. I basically want to do something like predictive text on android devices, so my program will act as a filter.

What i'm asking is basically how to direct all keyboard events to my program. While i am not looking for code, i would like to know what part of linux programming/ linux system do i have to learn to be able to complete this task? this, because i am doing this in an attempt to better learn linux.

like image 683
FutureSci Avatar asked Jun 21 '15 15:06

FutureSci


Video Answer


1 Answers

You shouldn't modify keyboard drivers since this will require you to have a solution for every keyboard manufacturer.(and there are quite a lot of these..)

Instead you should patch a kernel function that is called by all drivers before passing the input further up the stack.

To start with, you could patch input_event which is usually called by all input drivers see documentation here (not only keyboard but also mouse and other devices)

In any case you will have to "decode" the input scan code where you might find this documentation useful.

For more information on kernel patching read here and here.

like image 77
borisp Avatar answered Oct 13 '22 00:10

borisp