Lyndon Nerenberg <[EMAIL PROTECTED]> 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 <fcntl.h>
#include <stdio.h>
#include <machine/console.h>
#include <termios.h>
#include <errno.h>
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 [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message