-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetscancodes.c
95 lines (77 loc) · 2.7 KB
/
getscancodes.c
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*---------------------------------------------------------------------------------
Name : getscancodes.c
Author : Marvin Raaijmakers
Description : Shows the scancode of the pressed or released key.
Date of last change: 3-Sept-2005
Copyright (C) 2005 Marvin Raaijmakers
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
You can contact me at: marvinr(at)users(dot)sf(dot)net
(replace (at) by @ and (dot) by .)
-----------------------------------------------------------------------------------*/
#include <stdint.h>
#include <linux/input.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#ifndef EV_SYN
#define EV_SYN 0
#endif
int main (int argc, char **argv)
{
int fd, rd;
struct input_event ev[64];
int version;
unsigned short id[4];
char name[256] = "Unknown";
if (argc < 2)
{
printf("Usage: %s /dev/input/eventX\n", argv[0]);
printf("Where X = input device number\n");
return 1;
}
if ((fd = open(argv[argc - 1], O_RDONLY)) < 0)
{
perror("getscancodes");
return 1;
}
if (ioctl(fd, EVIOCGVERSION, &version))
{
perror("getscancodes: can't get version");
return 1;
}
printf("Input driver version is %d.%d.%d\n",
version >> 16, (version >> 8) & 0xff, version & 0xff);
ioctl(fd, EVIOCGID, id);
printf("Input device ID: bus 0x%x vendor 0x%x product 0x%x version 0x%x\n",
id[ID_BUS], id[ID_VENDOR], id[ID_PRODUCT], id[ID_VERSION]);
ioctl(fd, EVIOCGNAME(sizeof(name)), name);
printf("Input device name: \"%s\"\n", name);
while (1) {
rd = read(fd, ev, sizeof(struct input_event) * 64);
if (rd < (int) sizeof(struct input_event)) {
perror("getscancodes: error reading");
return 1;
}
for (unsigned i = 0; i < rd / sizeof(struct input_event); i++) {
printf("got input_event[%d] type=%d code=%d value=%d (0x%x)\n",
i, ev[i].type, ev[i].code, ev[i].value, ev[i].value);
if (ev[i].type != EV_SYN &&
ev[i].type == EV_MSC &&
(ev[i].code == MSC_RAW || ev[i].code == MSC_SCAN))
{
printf("%d (0x%x)\n", ev[i].value, ev[i].value);
}
}
}
}