linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Bruno Prémont" <bonbons@linux-vserver.org>
To: Mathias Laurenz Baumann <marenz@supradigital.org>
Cc: linux-input@vger.kernel.org
Subject: Re: Modifying keycodes or scancodes of keyboard devices
Date: Wed, 12 Sep 2012 22:49:21 +0200	[thread overview]
Message-ID: <20120912224921.45d3e383@neptune.home> (raw)
In-Reply-To: <op.wkg8x5kq486orv@labs03>

Hallo Mathias,

On Tue, 11 September 2012 "Mathias Laurenz Baumann" <marenz@supradigital.org> 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

      reply	other threads:[~2012-09-12 20:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-11 15:21 Modifying keycodes or scancodes of keyboard devices Mathias Laurenz Baumann
2012-09-12 20:49 ` Bruno Prémont [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120912224921.45d3e383@neptune.home \
    --to=bonbons@linux-vserver.org \
    --cc=linux-input@vger.kernel.org \
    --cc=marenz@supradigital.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).