Re: Modifying keycodes or scancodes of keyboard devices

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hallo Mathias,

On Tue, 11 September 2012 "Mathias Laurenz Baumann" <marenz@xxxxxxxxxxxxxxxx> wrote:
> I want to write a kernel module that hooks in somewhere between the  
> keyboard driver and whatever
> uses the resulting key events (e.g. evdev or xkb).

You can usually just tell the kernel to map scancodes to different keycodes
unless the driver you are targetting does something really weird.


Have a look at the following ioctls to change the scancode-keycode mappings
or even just find out what the current mappings are:
  EVIOCGKEYCODE
  EVIOCSKEYCODE
They both take and int[2] as argument for which the first int is the scancode
and the second one the keycode (there is a new revision of those ioctls that
work differently, for you to look them up).

Just issue the ioctls on your event device.


Sample userspace code for looking up mappings (note that you will eventually
need to adjust the scancode search range, brute-force 0x0..0xffffffff, best is
to capture a few evdev events to determine how the scancodes look like):

  int evdev = open("/dev/input/eventX", O_RDONLY);
  int codes[2];

  printf("Scancode mapping table:\n");
  for (codes[0] = 0x70000; codes[0] < 0x70060; codes[0]++) {
    if (ioctl(evdev, EVIOCGKEYCODE, codes) >= 0) {
      if (codes[1] == 0)
        continue;
      printf("0x%04x        => %s  (%d)\n", codes[0], get_key_name(codes[1]), codes[1]);
    } else if (errno != EINVAL) {
      fprintf(stderr, "Failed to get mapping for scancode %d: %s\n", codes[0], strerror(errno));
    } else
      continue;
  }


For the meaning of the keycodes, see linux/input.h (KEY_*)

Bruno
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media Devel]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Linux Wireless Networking]     [Linux Omap]

  Powered by Linux