summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Pitt <martin.pitt@ubuntu.com>2009-05-14 23:36:00 +0200
committerMartin Pitt <martin.pitt@ubuntu.com>2009-05-14 23:36:00 +0200
commit59ff79c3a307f99f016e33df348ca0727e94afd7 (patch)
tree6747ddc5bef206286e3869ca2f77a310534828f8
parenta65f01de17aec844db5ba270371a743071d5f58b (diff)
keymap: add --interactive mode
Add -i/--interactive mode to keymap tool, for easy debugging of unknown and wrong keymaps. Use like sudo /lib/udev/keymap -i input/event4 and note down the wrong/missing keys.
-rw-r--r--keymap/keymap.c69
1 files changed, 62 insertions, 7 deletions
diff --git a/keymap/keymap.c b/keymap/keymap.c
index 516dbc0..c48d934 100644
--- a/keymap/keymap.c
+++ b/keymap/keymap.c
@@ -228,18 +228,65 @@ static const char* default_keymap_path(const char* path)
return path;
}
+static void print_key(struct input_event *event)
+{
+ static int cur_scancode = 0;
+
+ /* save scan code for next EV_KEY event */
+ if (event->type == EV_MSC && event->code == MSC_SCAN)
+ cur_scancode = event->value;
+
+ /* key press */
+ if (event->type == EV_KEY && event->value)
+ printf("scan code: 0x%02X key code: %s\n", cur_scancode,
+ format_keyname(key_names[event->code]));
+}
+
+static void interactive(int fd)
+{
+ struct input_event ev;
+ int run = 1;
+
+ /* grab input device */
+ ioctl(fd, EVIOCGRAB, 1);
+
+ puts("Press ESC to finish");
+ while (run) {
+ switch (read(fd, &ev, sizeof(ev))) {
+ case -1:
+ perror("read");
+ run = 0;
+ break;
+ case 0:
+ run = 0;
+ break;
+ default:
+ print_key(&ev);
+ /* stop on Escape key release */
+ if (ev.type == EV_KEY && ev.code == KEY_ESC && ev.value == 0)
+ run = 0;
+ break;
+ }
+ }
+
+ /* release input device */
+ ioctl(fd, EVIOCGRAB, 0);
+}
+
int main(int argc, char **argv)
{
static const struct option options[] = {
{ "help", no_argument, NULL, 'h' },
+ { "interactive", no_argument, NULL, 'i' },
{}
};
int fd = -1;
+ int opt_interactive = 0;
while (1) {
int option;
- option = getopt_long(argc, argv, "h", options, NULL);
+ option = getopt_long(argc, argv, "hi", options, NULL);
if (option == -1)
break;
@@ -247,22 +294,30 @@ int main(int argc, char **argv)
case 'h':
printf("Usage: keymap <event device> [<map file>]\n\n");
return 0;
+
+ case 'i':
+ opt_interactive = 1;
+ break;
default:
return 1;
}
}
- if (argc < 2 || argc > 3) {
+ if (argc < optind+1 || argc > optind+2) {
fprintf(stderr, "Usage: keymap <event device> [<map file>]\n\n");
return 2;
}
- if ((fd = evdev_open(argv[1])) < 0)
+ if ((fd = evdev_open(argv[optind])) < 0)
return 3;
- if (argc == 3)
- merge_table(fd, default_keymap_path(argv[2]));
- else
- dump_table(fd);
+ if (argc == optind+2)
+ merge_table(fd, default_keymap_path(argv[optind+1]));
+ else {
+ if (opt_interactive)
+ interactive(fd);
+ else
+ dump_table(fd);
+ }
return 0;
}