2 * Copyright 2002 Red Hat Inc., Durham, North Carolina.
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation on the rights to use, copy, modify, merge,
10 * publish, distribute, sublicense, and/or sell copies of the Software,
11 * and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial
16 * portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
22 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * This is a simple test program that reads from /dev/input/event*,
28 * decoding events into a human readable form.
33 * Rickard E. (Rik) Faith <faith@redhat.com>
41 #include <sys/types.h>
45 #include <linux/input.h>
47 struct input_event event
;
50 main(int argc
, char **argv
)
52 char name
[64]; /* RATS: Use ok, but could be better */
53 char buf
[256] = { 0, }; /* RATS: Use ok */
54 unsigned char mask
[EV_MAX
/ 8 + 1]; /* RATS: Use ok */
61 #define test_bit(bit) (mask[(bit)/8] & (1 << ((bit)%8)))
63 for (i
= 0; i
< 32; i
++) {
64 snprintf(name
, sizeof(name
), "/dev/input/event%d", i
);
65 if ((fd
= open(name
, O_RDONLY
, 0)) >= 0) {
66 ioctl(fd
, EVIOCGVERSION
, &version
);
67 ioctl(fd
, EVIOCGNAME(sizeof(buf
)), buf
);
68 ioctl(fd
, EVIOCGBIT(0, sizeof(mask
)), mask
);
70 printf(" evdev version: %d.%d.%d\n",
71 version
>> 16, (version
>> 8) & 0xff, version
& 0xff);
72 printf(" name: %s\n", buf
);
74 for (j
= 0; j
< EV_MAX
; j
++) {
76 const char *type
= "unknown";
80 type
= "keys/buttons";
113 snprintf(name
, sizeof(name
), "/dev/input/event%d", atoi(argv
[1]));
114 if ((fd
= open(name
, O_RDWR
, 0)) >= 0) {
115 printf("%s: open, fd = %d\n", name
, fd
);
116 for (i
= 0; i
< LED_MAX
; i
++) {
117 event
.time
.tv_sec
= time(0);
118 event
.time
.tv_usec
= 0;
122 write(fd
, &event
, sizeof(event
));
125 while ((rc
= read(fd
, &event
, sizeof(event
))) > 0) {
126 printf("%-24.24s.%06lu type 0x%04x; code 0x%04x;"
128 ctime(&event
.time
.tv_sec
),
129 event
.time
.tv_usec
, event
.type
, event
.code
, event
.value
);
130 switch (event
.type
) {
132 if (event
.code
> BTN_MISC
) {
133 printf("Button %d %s",
135 event
.value
? "press" : "release");
138 printf("Key %d (0x%x) %s",
141 event
.value
? "press" : "release");
145 switch (event
.code
) {
168 printf("Relative %s %d", tmp
, event
.value
);
171 switch (event
.code
) {
248 printf("Absolute %s %d", tmp
, event
.value
);
269 printf("rc = %d, (%s)\n", rc
, strerror(errno
));