1 // SPDX-License-Identifier: MIT
2 /*
3 * Copyright © 2021 Red Hat, Inc.
4 */
5
6 /* Lists all event types and codes currently known by libevdev. */
7
8 #include "config.h"
9
10 #include <stdio.h>
11 #include <linux/input.h>
12 #include "libevdev/libevdev.h"
13
14 static void
list_event_codes(unsigned int type,unsigned int max)15 list_event_codes(unsigned int type, unsigned int max)
16 {
17 const char *typestr = libevdev_event_type_get_name(type);
18
19 if (!typestr)
20 return;
21
22 printf("- %s:\n", typestr);
23
24 for (unsigned int code = 0; code <= max; code++) {
25 const char *str = libevdev_event_code_get_name(type, code);
26
27 if (!str)
28 continue;
29
30 printf(" %d: %s\n", code, str);
31 }
32 }
33
34 int
main(int argc,char ** argv)35 main (int argc, char **argv)
36 {
37 printf("codes:\n");
38 for (unsigned int type = 0; type <= EV_MAX; type++) {
39 int max = libevdev_event_type_get_max(type);
40 if (max == -1)
41 continue;
42
43 list_event_codes(type, (unsigned int)max);
44 }
45
46 return 0;
47 }
48