The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Marvin Raaijmakers <marvin.nospam@gmail.com>
To: linux-kernel@vger.kernel.org
Subject: New way of setting keycodes to scancodes
Date: Fri, 09 Jun 2006 21:49:44 +0200	[thread overview]
Message-ID: <1149882584.19680.33.camel@localhost.localdomain> (raw)

Hello,

Currently it isn't possible to assign keycodes to keys of USB keyboards
by usign a userspace application. This is because USB keyboards do not
send scancodes, but HID usage codes. I have modified the hid-input
driver so that keycodes can be set to HID usage codes in exactly the
same way as keycodes are set to scancodes.
To make this possible I had to modify the input_dev structure (in
<linux/input.h>) by adding a "setkeycodes" member to it. This member is
a pointer to a function that sets the keycodes to scancodes (and HID
usage codes). Each driver has its own "setkeycodes" function and if a
driver does not provide the functionality to set keycodes, the pointer
will be NULL. The evdev_ioctl function will call the "setkeycode"
function if its cmd parameter is equal to EVIOCSKEYCODE.
All keyboard drivers now have a setkeycode function, including the
hid-input driver. Note that hid-usage codes are handled the same way as
scancodes.
The keycodemax, keycodesize and keycode member are not removed from the
input_dev structure so that the old way of setting a keycode (by using
the setkeycodes program) can still be used.
The files I modified can be downloaded from:
http://marvin.linux-box.nl/files/kernel_mod.tar.gz (note that I used the
source files from kernel 2.6.15)

Below you can see a simple application for setting keycodes:
----------------
#include <linux/input.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>

int
main (int argc, char **argv)
{
	int fd;
	struct input_keycode2scancode scan2key;
	
	if (argc < 4)
	{
		printf ("Usage: %s /dev/input/eventX scancode keycode\n", argv[0]);
		printf ("Where X = input device number\n");
		return 1;
	}
	
	if ((fd = open(argv[1], O_RDONLY)) < 0)
	{
		perror (argv[0]);
		return 1;
	}
	
	scan2key.scancode = (unsigned) strtol(argv[2], NULL, 0);
	scan2key.keycode = (unsigned) strtol(argv[3], NULL, 0);
	ioctl (fd, EVIOCSKEYCODE, &scan2key);
	
	return 0;
}
----------------

I hope my code will be implemented in the kernel, because with the
current code a lot of extra function keys on USB keyboards do not work
because they do not have a keycode. My code makes it possible to set a
keycode to such key, so that it will work.

Regards,
Marvin Raaijmakers


                 reply	other threads:[~2006-06-09 19:48 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1149882584.19680.33.camel@localhost.localdomain \
    --to=marvin.nospam@gmail.com \
    --cc=linux-kernel@vger.kernel.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