File: dumpkeycodes.c

package info (click to toggle)
hotkey-setup 0.1-17
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 148 kB
  • ctags: 37
  • sloc: ansic: 243; sh: 111; makefile: 57
file content (36 lines) | stat: -rw-r--r-- 590 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/kd.h>

int main() {
	int sc;
	int fd;
	fd = open("/dev/console", O_RDWR);
	
	if (fd == -1) {
		return 1;
	}

	struct kbkeycode a;
	for (sc=0; sc<256; sc++) {
		a.scancode = sc;
		a.keycode = 0;
		if (ioctl(fd,KDGETKEYCODE,&a)) {
			if (errno == EINVAL) {
				a.keycode = 256;
			} else {
				perror("dumpkeycodes");
				return 2;
			}
		}
		if (sc < 128) {
			printf("%x %d\n",a.scancode,a.keycode);
		} else {
			printf("e0%02x %d\n",sc-128,a.keycode);
		}
	}
	return 0;
}