1 .. -*- coding: utf-8; mode: rst -*-
3 file: uapi/v4l/keytable.c
4 =========================
8 /* keytable.c - This program allows checking/replacing keys at IR
10 Copyright (C) 2006-2009 Mauro Carvalho Chehab <mchehab@infradead.org>
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation, version 2 of the License.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
28 #include <linux/input.h>
29 #include <sys/ioctl.h>
33 void prtcode (int *codes)
37 for (p=keynames;p->name!=NULL;p++) {
38 if (p->value == (unsigned)codes[1]) {
39 printf("scancode 0x%04x = %s (0x%02x)\\n", codes[0], p->name, codes[1]);
44 if (isprint (codes[1]))
45 printf("scancode %d = '%c' (0x%02x)\\n", codes[0], codes[1], codes[1]);
47 printf("scancode %d = 0x%02x\\n", codes[0], codes[1]);
50 int parse_code(char *string)
54 for (p=keynames;p->name!=NULL;p++) {
55 if (!strcasecmp(p->name, string)) {
62 int main (int argc, char *argv[])
68 if (argc<2 || argc>4) {
69 printf ("usage: %s <device> to get table; or\\n"
70 " %s <device> <scancode> <keycode>\\n"
71 " %s <device> <keycode_file>n",*argv,*argv,*argv);
75 if ((fd = open(argv[1], O_RDONLY)) < 0) {
76 perror("Couldn't open input device");
83 value=parse_code(argv[3]);
86 value = strtol(argv[3], NULL, 0);
91 codes [0] = (unsigned) strtol(argv[2], NULL, 0);
92 codes [1] = (unsigned) value;
94 if(ioctl(fd, EVIOCSKEYCODE, codes))
95 perror ("EVIOCSKEYCODE");
97 if(ioctl(fd, EVIOCGKEYCODE, codes)==0)
105 char *scancode, *keycode, s[2048];
107 fin=fopen(argv[2],"r");
109 perror ("opening keycode file");
113 /* Clears old table */
114 for (j = 0; j < 256; j++) {
115 for (i = 0; i < 256; i++) {
116 codes[0] = (j << 8) | i;
117 codes[1] = KEY_RESERVED;
118 ioctl(fd, EVIOCSKEYCODE, codes);
122 while (fgets(s,sizeof(s),fin)) {
123 scancode=strtok(s,"\\n\\t =:");
125 perror ("parsing input file scancode");
128 if (!strcasecmp(scancode, "scancode")) {
129 scancode = strtok(NULL,"\\n\\t =:");
131 perror ("parsing input file scancode");
136 keycode=strtok(NULL,"\\n\\t =:(");
138 perror ("parsing input file keycode");
142 // printf ("parsing %s=%s:", scancode, keycode);
143 value=parse_code(keycode);
144 // printf ("\\tvalue=%d\\n",value);
147 value = strtol(keycode, NULL, 0);
152 codes [0] = (unsigned) strtol(scancode, NULL, 0);
153 codes [1] = (unsigned) value;
155 // printf("\\t%04x=%04x\\n",codes[0], codes[1]);
156 if(ioctl(fd, EVIOCSKEYCODE, codes)) {
157 fprintf(stderr, "Setting scancode 0x%04x with 0x%04x via ",codes[0], codes[1]);
158 perror ("EVIOCSKEYCODE");
161 if(ioctl(fd, EVIOCGKEYCODE, codes)==0)
167 /* Get scancode table */
168 for (j = 0; j < 256; j++) {
169 for (i = 0; i < 256; i++) {
170 codes[0] = (j << 8) | i;
171 if (!ioctl(fd, EVIOCGKEYCODE, codes) && codes[1] != KEY_RESERVED)