public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Vojtech Pavlik <vojtech@suse.cz>
To: Andries Brouwer <aebr@win.tue.nl>
Cc: Vojtech Pavlik <vojtech@suse.cz>,
	Skip Ford <skip.ford@verizon.net>,
	linux-kernel@vger.kernel.org
Subject: Re: KDSETKEYCODE work with new input layer?
Date: Mon, 7 Oct 2002 14:06:03 +0200	[thread overview]
Message-ID: <20021007140603.A627@ucw.cz> (raw)
In-Reply-To: <20021001162955.GA19132@win.tue.nl>; from aebr@win.tue.nl on Tue, Oct 01, 2002 at 06:29:55PM +0200

On Tue, Oct 01, 2002 at 06:29:55PM +0200, Andries Brouwer wrote:
> On Tue, Oct 01, 2002 at 05:55:37PM +0200, Vojtech Pavlik wrote:
> 
> > Ok. Where is the most recent version of [gs]etkeycodes?
> 
> In kbd-1.06. It is from May 2001, and I have been planning kbd-1.07
> for a while but there were no urgent changes, just more fonts and
> keymaps and the like. When you are done it is a good occasion for
> kbd-1.07.
> 
> Andries
> 
> Begin3
> Title:          Keyboard and console utilities for Linux
> Version:        1.06
> Entered-date:   2001-05-19
> Description:    loadkeys dumpkeys setfont chvt openvt kbd.FAQ A20 etc.
> Keywords:       keyboard mapping console font unicode
> Author:         several
> Maintained-by:  Andries E. Brouwer (aeb@cwi.nl)
> Primary-site:   ftp://ftp.win.tue.nl/pub/linux-local/utils/kbd
>                 773433 kbd-1.06.tar.gz
> Alternate-site: ftp://ftp.*.kernel.org/pub/linux/utils/kbd
> Alternate-site: ftp://sunsite.unc.edu/pub/Linux/system/keyboards
> Alternate site: ftp://ftp.cwi.nl/pub/aeb/kbd
> Copying-policy: GPL
> End

Ok, here is a patch that should make it work correctly on all existing
kernels.

You may want to check that loadkeys supports keycodes over 127 (and for
future, over 255), too. I updated only getkeycodes/setkeycodes.

diff -urN kbd-1.06/src/getkeycodes.c kbd-1.06-new/src/getkeycodes.c
--- kbd-1.06/src/getkeycodes.c	Fri Oct  8 21:45:54 1999
+++ kbd-1.06-new/src/getkeycodes.c	Mon Oct  7 12:38:47 2002
@@ -21,8 +21,9 @@
 
 int
 main(int argc, char **argv) {
-    int fd, sc;
+    int fd, sc = 0;
     struct kbkeycode a;
+    int old_kernel = 0;
 
     set_progname(argv[0]);
 
@@ -36,30 +37,47 @@
     if (argc != 1)
       usage();
     fd = getfd();
+
+    a.scancode = 0; /* Old kernels don't support */
+    a.keycode = 0;  /* scancodes below SC_LIM. */
+    if (ioctl(fd,KDGETKEYCODE,&a))
+        old_kernel = 1;
+
     printf(_("Plain scancodes xx (hex) versus keycodes (dec)\n"));
-    printf(_("0 is an error; for 1-88 (0x01-0x58) scancode equals keycode\n"));
 
-    for(sc=88; sc<256; sc++) {
-	if (sc == 128)
-	  printf(_("\n\nEscaped scancodes e0 xx (hex)\n"));
+    if (old_kernel) {
+        printf(_("0 is an error; for 1-88 (0x01-0x58) scancode equals keycode\n"));
+	sc = 0x89;
+    }
+
+    while (1) {
+	if (old_kernel) {
+	  if (sc == 128)
+            printf(_("\n\nEscaped scancodes e0 xx (hex)\n"));
+	  if (sc == 256) {
+            printf("\n");
+            return 0;
+          }
+        }	
 	if (sc % 8 == 0) {
-	    if (sc < 128)
-	      printf("\n 0x%02x: ", sc);
-	    else
-	      printf("\ne0 %02x: ", sc-128);
-	}
-
-	if (sc <= 88) {
-	    printf(" %3d", sc);
-	    continue;
+            if (old_kernel) {
+	      if (sc < 128)
+	        printf("\n 0x%02x: ", sc);
+	      else
+	        printf("\ne0 %02x: ", sc-128);
+	    } else
+		printf("\n 0x%04x: ", sc); 
 	}
-
 	a.scancode = sc;
 	a.keycode = 0;
 	if (ioctl(fd,KDGETKEYCODE,&a)) {
-	    if (errno == EINVAL)
+	    if (errno == EINVAL) {
+		if (!old_kernel) {
+			printf("\n");
+			return 0;
+		}
 	      printf("   -");
-	    else {
+	    } else {
 		perror("KDGETKEYCODE");
 		fprintf(stderr, _("failed to get keycode for scancode 0x%x\n"),
 			sc);
@@ -67,6 +85,8 @@
 	    }
 	} else
 	  printf(" %3d", a.keycode);
+
+	sc++;
     }
     printf("\n");
     return 0;
diff -urN kbd-1.06/src/setkeycodes.c kbd-1.06-new/src/setkeycodes.c
--- kbd-1.06/src/setkeycodes.c	Fri Oct  8 21:42:02 1999
+++ kbd-1.06-new/src/setkeycodes.c	Mon Oct  7 12:40:08 2002
@@ -27,7 +27,7 @@
 int
 main(int argc, char **argv) {
     char *ep;
-    int fd, sc;
+    int fd, sc, old_kernel = 0;
     struct kbkeycode a;
 
     set_progname(argv[0]);
@@ -43,17 +43,20 @@
       usage(_("even number of arguments expected"));
     fd = getfd();
 
+    a.scancode = 0; /* Old kernels don't support */
+    a.keycode = 0;  /* scancodes below SC_LIM. */
+    if (ioctl(fd,KDGETKEYCODE,&a))
+	old_kernel = 1;
+
     while (argc > 2) {
 	a.keycode = atoi(argv[2]);
 	a.scancode = sc = strtol(argv[1], &ep, 16);
 	if (*ep)
 	  usage(_("error reading scancode"));
-	if (a.scancode > 127) {
+	if ((a.scancode & ~0xff) == 0xe000) {
 	    a.scancode -= 0xe000;
-	    a.scancode += 128;
+            a.scancode += old_kernel ? 128 : 256;
 	}
-	if (a.scancode > 255 || a.keycode > 127)
-	  usage(_("code outside bounds"));
 	if (ioctl(fd,KDSETKEYCODE,&a)) {
 	    perror("KDSETKEYCODE");
 	    fprintf(stderr, _("failed to set scancode %x to keycode %d\n"),


-- 
Vojtech Pavlik
SuSE Labs

  reply	other threads:[~2002-10-07 12:00 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-30 14:40 KDSETKEYCODE work with new input layer? Skip Ford
2002-10-01  9:54 ` Vojtech Pavlik
2002-10-01 12:31   ` Skip Ford
2002-10-01 13:17     ` Vojtech Pavlik
2002-10-01 15:32       ` Skip Ford
2002-10-01 15:41         ` Vojtech Pavlik
2002-10-01 15:54           ` Andries Brouwer
2002-10-01 15:55             ` Vojtech Pavlik
2002-10-01 16:29               ` Andries Brouwer
2002-10-07 12:06                 ` Vojtech Pavlik [this message]
2002-10-07 12:52                   ` Andries Brouwer
2002-10-07 13:23                   ` Skip Ford
2002-10-07 13:39                     ` Vojtech Pavlik
2002-10-01 16:49           ` Skip Ford
2002-10-01 16:51             ` Vojtech Pavlik
2002-10-01 17:41               ` Skip Ford
2002-10-01 17:39                 ` Vojtech Pavlik
2002-10-01 18:11                   ` Skip Ford
2002-10-01 18:38                     ` Vojtech Pavlik
2002-10-01 20:04                       ` Skip Ford
2002-10-01 20:53                         ` Vojtech Pavlik

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=20021007140603.A627@ucw.cz \
    --to=vojtech@suse.cz \
    --cc=aebr@win.tue.nl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=skip.ford@verizon.net \
    /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