From owner-freebsd-hackers Wed Jan 5 15:49:18 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from biggusdiskus.flyingfox.com (parker-T1-2-gw.sf3d.best.net [209.157.165.30]) by hub.freebsd.org (Postfix) with ESMTP id 56E4B15481 for ; Wed, 5 Jan 2000 15:49:15 -0800 (PST) (envelope-from jas@flyingfox.com) Received: (from jas@localhost) by biggusdiskus.flyingfox.com (8.8.8/8.8.5) id PAA26271; Wed, 5 Jan 2000 15:45:05 -0800 (PST) Date: Wed, 5 Jan 2000 15:45:05 -0800 (PST) From: Jim Shankland Message-Id: <200001052345.PAA26271@biggusdiskus.flyingfox.com> To: freebsd-hackers@FreeBSD.ORG, lyndon@orthanc.ab.ca Subject: Re: Reading kbd scancodes from userland In-Reply-To: <200001052332.e05NWSr84505@orthanc.ab.ca> Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Lyndon Nerenberg asks: > Is it possible to read the raw keyboard scancodes from a userland > process? I can't find an ioctl for this. (This is 3.3-RELEASE+PAO3, > atkbd and syscons.) Yup. Save the following as kbddump.c, then: cc -O kbddump.c -o kbddump ./kbddump Jim Shankland NLynx Systems, Inc. #include #include #include #include #include main(int argc, char *argv[]) { int fd; unsigned char onecode; int oldmode; int newmode = K_RAW; struct termios old_t, new_t; int rr; if (argc > 1 && strcmp(argv[1], "-k") == 0) newmode = K_CODE; if ((fd = open("/dev/ttyv0", O_RDWR)) < 0) { (void) fprintf(stderr, "/dev/kbd0: %s\n", strerror(errno)); exit(1); } if (ioctl(fd, KDGKBMODE, &oldmode) < 0) { (void) fprintf(stderr, "KDGKBMODE: %s\n", strerror(errno)); exit(1); } printf("Old mode is %d\n", oldmode); if (tcgetattr(fd, &old_t) != 0) { (void) fprintf(stderr, "tcgetattr: %s\n", strerror(errno)); exit(1); } new_t = old_t; cfmakeraw(&new_t); if (tcsetattr(fd, 0, &new_t) != 0) { (void) fprintf(stderr, "tcsetattr: %s\n", strerror(errno)); exit(1); } if (ioctl(fd, KDSKBMODE, newmode) < 0) { (void) tcsetattr(fd, 0, &old_t); (void) fprintf(stderr, "KDSKBMODE: %s\n", strerror(errno)); exit(1); } printf("Scancodes are in hexadecimal; program will terminate when the\r\n"); printf("'a' key is released (scancode 9e) ...\r\n\n"); while ((rr = read(fd, &onecode, 1)) > 0) { printf("Code: %02x\r\n", (unsigned) onecode); if (onecode == 0x9e) break; } if (rr < 0) { (void) fprintf(stderr, "keyboard read: %s\r\n", strerror(errno)); } (void) tcsetattr(fd, 0, &old_t); if (ioctl(fd, KDSKBMODE, oldmode) < 0) { (void) fprintf(stderr, "Danger, Will Robinson! Can't restore keyboard: %s\n", strerror(errno)); exit(1); } exit(0); } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message