3

I have to write a linux kernel module, which change character printed on the screen after pressing a key (let's say - I want 'a' to be printed when I press 'b' on keyboard). What is the best way to do it? I'he thought that good idea is to create module for keyboard. I did some research, i saw few keyloggers (as kernel modules) but all of them where able only to listen what key was pressed, and any change of scancode was imposible (which is pretty obvious in keyloggers). I read 3rd chapter from Linux Device Drivers, and i started to read 6th, but they are talking only about virtual devices, when i want to connect my module with the real device. I saw also this https://stackoverflow.com/questions/33836541/linux-kernel-how-to-capture-a-key-press-and-replace-it-with-another-key, but it wasn't working. My teacher said there is much eaysier way than using interrupts, but I have no idea how to do it (neither using interrupts and any other way).

What should I do? just read next chapters of LDD? Or any other book? Or maybe just lie down and cry?

Community
  • 1
  • 1
mmichal10
  • 322
  • 2
  • 13
  • you do it in the user space. e.g. you do `xinput float` on your input hardware to disconnect it from your desktop system, then write a program to read input from it, translate it to another event, then pass it to `uinput`. You use `uinput ` to create a virtual input device to inject the translated input event back into the system. referencd: http://thiemonge.org/getting-started-with-uinput – user3528438 Nov 23 '16 at 19:56
  • I would love to do it in user space, but i must be a kernel modul. – mmichal10 Nov 23 '16 at 20:00
  • That's a ill-formed requirement. – user3528438 Nov 23 '16 at 20:11
  • 1
    @user3528438 His teacher asked him so it looks more like a task to learn from as opposed to something that's going to run in production or have some utility other than writing a kernel module etc. – Harry Nov 24 '16 at 01:36

1 Answers1

0

Here's a very simple example of keyboard driver kernel module: https://github.com/raleighlittles/Olympus-MAJ-1428-Keyboard-Linux-driver/blob/main/hid-olympus-maj1428.c

I had a keyboard that generated weird scancodes for certain non-character keys (read the file, it explains more). Instead of using those scancodes, I wrote code to remap them to the extended function keys (F13, F14, etc.). You could use the code and instead simply switch the scan codes that you want by changing the key_mapping variable.

Raleigh L.
  • 599
  • 2
  • 13
  • 18