1 .. SPDX-License-Identifier: GPL-2.0 OR GFDL-1. 2 3 file: uapi/v4l/keytable.c 4 ========================= 5 6 .. code-block:: c 7 8 /* keytable.c - This program allows checki 9 10 Copyright (C) 2006-2009 Mauro Carvalho < 11 12 This program is free software; you can 13 it under the terms of the GNU General P 14 the Free Software Foundation, version 2 15 16 This program is distributed in the hope 17 but WITHOUT ANY WARRANTY; without even 18 MERCHANTABILITY or FITNESS FOR A PARTIC 19 GNU General Public License for more det 20 */ 21 22 #include <ctype.h> 23 #include <errno.h> 24 #include <fcntl.h> 25 #include <stdio.h> 26 #include <stdlib.h> 27 #include <string.h> 28 #include <linux/input.h> 29 #include <sys/ioctl.h> 30 31 #include "parse.h" 32 33 void prtcode (int *codes) 34 { 35 struct parse_key *p; 36 37 for (p=keynames;p->name!=NULL;p++) 38 if (p->value == (unsigned) 39 printf("scancode 0 40 return; 41 } 42 } 43 44 if (isprint (codes[1])) 45 printf("scancode %d = '%c' 46 else 47 printf("scancode %d = 0x%0 48 } 49 50 int parse_code(char *string) 51 { 52 struct parse_key *p; 53 54 for (p=keynames;p->name!=NULL;p++) 55 if (!strcasecmp(p->name, s 56 return p->value; 57 } 58 } 59 return -1; 60 } 61 62 int main (int argc, char *argv[]) 63 { 64 int fd; 65 unsigned int i, j; 66 int codes[2]; 67 68 if (argc<2 || argc>4) { 69 printf ("usage: %s <device 70 " %s <device 71 " %s <device 72 return -1; 73 } 74 75 if ((fd = open(argv[1], O_RDONLY)) 76 perror("Couldn't open inpu 77 return(-1); 78 } 79 80 if (argc==4) { 81 int value; 82 83 value=parse_code(argv[3]); 84 85 if (value==-1) { 86 value = strtol(arg 87 if (errno) 88 perror("va 89 } 90 91 codes [0] = (unsigned) str 92 codes [1] = (unsigned) val 93 94 if(ioctl(fd, EVIOCSKEYCODE 95 perror ("EVIOCSKEY 96 97 if(ioctl(fd, EVIOCGKEYCODE 98 prtcode(codes); 99 return 0; 100 } 101 102 if (argc==3) { 103 FILE *fin; 104 int value; 105 char *scancode, *keycode, 106 107 fin=fopen(argv[2],"r"); 108 if (fin==NULL) { 109 perror ("opening k 110 return -1; 111 } 112 113 /* Clears old table */ 114 for (j = 0; j < 256; j++) 115 for (i = 0; i < 25 116 codes[0] = 117 codes[1] = 118 ioctl(fd, 119 } 120 } 121 122 while (fgets(s,sizeof(s),f 123 scancode=strtok(s, 124 if (!scancode) { 125 perror ("p 126 return -1; 127 } 128 if (!strcasecmp(sc 129 scancode = 130 if (!scanc 131 pe 132 re 133 } 134 } 135 136 keycode=strtok(NUL 137 if (!keycode) { 138 perror ("p 139 return -1; 140 } 141 142 // printf ("parsin 143 value=parse_code(k 144 // printf ("\\tval 145 146 if (value==-1) { 147 value = st 148 if (errno) 149 pe 150 } 151 152 codes [0] = (unsig 153 codes [1] = (unsig 154 155 // printf("\\t%04x 156 if(ioctl(fd, EVIOC 157 fprintf(st 158 perror ("E 159 } 160 161 if(ioctl(fd, EVIOC 162 prtcode(co 163 } 164 return 0; 165 } 166 167 /* Get scancode table */ 168 for (j = 0; j < 256; j++) { 169 for (i = 0; i < 256; i++) 170 codes[0] = (j << 8 171 if (!ioctl(fd, EVI 172 prtcode(co 173 } 174 } 175 return 0; 176 }
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.