2 /* keytable.c - This program allows checking/replacing keys at IR
4 Copyright (C)
2006-
2009 Mauro Carvalho Chehab
<mchehab@infradead.org
>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, version
2 of the License.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
16 #include
<ctype.h
>
17 #include
<errno.h
>
18 #include
<fcntl.h
>
19 #include
<stdio.h
>
20 #include
<stdlib.h
>
21 #include
<string.h
>
22 #include
<linux/input.h
>
23 #include
<sys/ioctl.h
>
27 void prtcode (int *codes)
31 for (p=keynames;p-
>name!=NULL;p++) {
32 if (p-
>value == (unsigned)codes[
1]) {
33 printf(
"scancode 0x%04x = %s (0x%02x)\n", codes[
0], p-
>name, codes[
1]);
38 if (isprint (codes[
1]))
39 printf(
"scancode %d = '%c' (0x%02x)\n", codes[
0], codes[
1], codes[
1]);
41 printf(
"scancode %d = 0x%02x\n", codes[
0], codes[
1]);
44 int parse_code(char *string)
48 for (p=keynames;p-
>name!=NULL;p++) {
49 if (!strcasecmp(p-
>name, string)) {
56 int main (int argc, char *argv[])
62 if (argc
<2 || argc
>4) {
63 printf (
"usage: %s <device> to get table; or\n"
64 " %s <device> <scancode> <keycode>\n"
65 " %s <device> <keycode_file>\n",*argv,*argv,*argv);
69 if ((fd = open(argv[
1], O_RDONLY))
< 0) {
70 perror(
"Couldn't open input device");
77 value=parse_code(argv[
3]);
80 value = strtol(argv[
3], NULL,
0);
85 codes [
0] = (unsigned) strtol(argv[
2], NULL,
0);
86 codes [
1] = (unsigned) value;
88 if(ioctl(fd, EVIOCSKEYCODE, codes))
89 perror (
"EVIOCSKEYCODE");
91 if(ioctl(fd, EVIOCGKEYCODE, codes)==
0)
99 char *scancode, *keycode, s[
2048];
101 fin=fopen(argv[
2],
"r");
103 perror (
"opening keycode file");
107 /* Clears old table */
108 for (j =
0; j
< 256; j++) {
109 for (i =
0; i
< 256; i++) {
110 codes[
0] = (j
<< 8) | i;
111 codes[
1] = KEY_RESERVED;
112 ioctl(fd, EVIOCSKEYCODE, codes);
116 while (fgets(s,sizeof(s),fin)) {
117 scancode=strtok(s,
"\n\t =:");
119 perror (
"parsing input file scancode");
122 if (!strcasecmp(scancode,
"scancode")) {
123 scancode = strtok(NULL,
"\n\t =:");
125 perror (
"parsing input file scancode");
130 keycode=strtok(NULL,
"\n\t =:(");
132 perror (
"parsing input file keycode");
136 // printf (
"parsing %s=%s:", scancode, keycode);
137 value=parse_code(keycode);
138 // printf (
"\tvalue=%d\n",value);
141 value = strtol(keycode, NULL,
0);
146 codes [
0] = (unsigned) strtol(scancode, NULL,
0);
147 codes [
1] = (unsigned) value;
149 // printf(
"\t%04x=%04x\n",codes[
0], codes[
1]);
150 if(ioctl(fd, EVIOCSKEYCODE, codes)) {
151 fprintf(stderr,
"Setting scancode 0x%04x with 0x%04x via ",codes[
0], codes[
1]);
152 perror (
"EVIOCSKEYCODE");
155 if(ioctl(fd, EVIOCGKEYCODE, codes)==
0)
161 /* Get scancode table */
162 for (j =
0; j
< 256; j++) {
163 for (i =
0; i
< 256; i++) {
164 codes[
0] = (j
<< 8) | i;
165 if (!ioctl(fd, EVIOCGKEYCODE, codes)
&& codes[
1] != KEY_RESERVED)