1 .. Permission is granted to copy, distribute and/or modify this
2 .. document under the terms of the GNU Free Documentation License,
3 .. Version 1.1 or any later version published by the Free Software
4 .. Foundation, with no Invariant Sections, no Front-Cover Texts
5 .. and no Back-Cover Texts. A copy of the license is included at
6 .. Documentation/media/uapi/fdl-appendix.rst.
8 .. TODO: replace it to GFDL-1.1-or-later WITH no-invariant-sections
10 file: uapi/v4l/keytable.c
11 =========================
15 /* keytable.c - This program allows checking/replacing keys at IR
17 Copyright (C) 2006-2009 Mauro Carvalho Chehab <mchehab@kernel.org>
19 This program is free software; you can redistribute it and/or modify
20 it under the terms of the GNU General Public License as published by
21 the Free Software Foundation, version 2 of the License.
23 This program is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 GNU General Public License for more details.
35 #include <linux/input.h>
36 #include <sys/ioctl.h>
40 void prtcode (int *codes)
44 for (p=keynames;p->name!=NULL;p++) {
45 if (p->value == (unsigned)codes[1]) {
46 printf("scancode 0x%04x = %s (0x%02x)\\n", codes[0], p->name, codes[1]);
51 if (isprint (codes[1]))
52 printf("scancode %d = '%c' (0x%02x)\\n", codes[0], codes[1], codes[1]);
54 printf("scancode %d = 0x%02x\\n", codes[0], codes[1]);
57 int parse_code(char *string)
61 for (p=keynames;p->name!=NULL;p++) {
62 if (!strcasecmp(p->name, string)) {
69 int main (int argc, char *argv[])
75 if (argc<2 || argc>4) {
76 printf ("usage: %s <device> to get table; or\\n"
77 " %s <device> <scancode> <keycode>\\n"
78 " %s <device> <keycode_file>n",*argv,*argv,*argv);
82 if ((fd = open(argv[1], O_RDONLY)) < 0) {
83 perror("Couldn't open input device");
90 value=parse_code(argv[3]);
93 value = strtol(argv[3], NULL, 0);
98 codes [0] = (unsigned) strtol(argv[2], NULL, 0);
99 codes [1] = (unsigned) value;
101 if(ioctl(fd, EVIOCSKEYCODE, codes))
102 perror ("EVIOCSKEYCODE");
104 if(ioctl(fd, EVIOCGKEYCODE, codes)==0)
112 char *scancode, *keycode, s[2048];
114 fin=fopen(argv[2],"r");
116 perror ("opening keycode file");
120 /* Clears old table */
121 for (j = 0; j < 256; j++) {
122 for (i = 0; i < 256; i++) {
123 codes[0] = (j << 8) | i;
124 codes[1] = KEY_RESERVED;
125 ioctl(fd, EVIOCSKEYCODE, codes);
129 while (fgets(s,sizeof(s),fin)) {
130 scancode=strtok(s,"\\n\\t =:");
132 perror ("parsing input file scancode");
135 if (!strcasecmp(scancode, "scancode")) {
136 scancode = strtok(NULL,"\\n\\t =:");
138 perror ("parsing input file scancode");
143 keycode=strtok(NULL,"\\n\\t =:(");
145 perror ("parsing input file keycode");
149 // printf ("parsing %s=%s:", scancode, keycode);
150 value=parse_code(keycode);
151 // printf ("\\tvalue=%d\\n",value);
154 value = strtol(keycode, NULL, 0);
159 codes [0] = (unsigned) strtol(scancode, NULL, 0);
160 codes [1] = (unsigned) value;
162 // printf("\\t%04x=%04x\\n",codes[0], codes[1]);
163 if(ioctl(fd, EVIOCSKEYCODE, codes)) {
164 fprintf(stderr, "Setting scancode 0x%04x with 0x%04x via ",codes[0], codes[1]);
165 perror ("EVIOCSKEYCODE");
168 if(ioctl(fd, EVIOCGKEYCODE, codes)==0)
174 /* Get scancode table */
175 for (j = 0; j < 256; j++) {
176 for (i = 0; i < 256; i++) {
177 codes[0] = (j << 8) | i;
178 if (!ioctl(fd, EVIOCGKEYCODE, codes) && codes[1] != KEY_RESERVED)