0

So I want to build a kernel module (I suppose) which would insert little delay after a keyboard key is pressed (let's say 500ms). I managed to do this in Windows through hooks, but it seems to be different in Linux. Note that I do not wish to use x11 methods, as I want it to also work from the linux console (even if there is no X server running). From what I was able to understand, it would require to build a kernel module and insert it dynamically into the kernel with insmod. I managed to build a key logger which would dump each pressed key to the kernel log, but inserting a delay would require sending the thread that handles the keyboard interrupt handler to sleep, which is a very bad idea, and also to rewrite the entire USB_KBD driver, because the current script calls the request_irq function with the IRQF_SHARED flag set, so I guess the original driver still does its job before executing my function.

I am currently requesting an interrupt handler like this

request_irq (1, (irq_handler_t) irq_handler, IRQF_SHARED, "keyboard_stats_irq", (void *)(irq_handler));

Any suggestions on how to handle this (any other way) ?

dclaudiud
  • 324
  • 3
  • 10
  • I don't understand the ssh part. ssh is just a program, well a client and a server, but I don't know if you want to slow down the client or de server... Or do you mean that you want it to work even in the linux console (when no X is running)? – rodrigo Jan 02 '18 at 23:15
  • yes, that is what I was trying to say , thanks :) I want to slow down the server, even if X is not running, and I expect the module to also work in X, considering that I implement it at the kernel level – dclaudiud Jan 02 '18 at 23:22

1 Answers1

1

You can write a user space daemon that reads the input events from /dev/input/input* (whatever the keyboard device is), while grabbing the device to block the events to go through the rest of the system (ioctl(fd, EVIOCGRAB, 1)).

Then, the daemon can create a virtual input device, using /dev/uinput and write the input events there after some delay. Since the delay will be implemented in user-space, that will be quite easy.

Starting your daemon will be equivalent to hot-plugging a virtual keyboard, and modern X servers (less than 10 years?) are able to cope with hot-plugged input devices. And the vconsole driver works fine too with those.

rodrigo
  • 94,151
  • 12
  • 143
  • 190