From: beeanyew Date: Sun, 11 Apr 2021 23:32:32 +0000 (+0200) Subject: Add keyboard event source file setting to config-file X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=9240897dc2bfdce45ae01f333f492ab22603685c;p=pistorm Add keyboard event source file setting to config-file --- diff --git a/config_file/config_file.c b/config_file/config_file.c index 7dbd238..1c8ef09 100644 --- a/config_file/config_file.c +++ b/config_file/config_file.c @@ -34,6 +34,7 @@ const char *config_item_names[CONFITEM_NUM] = { "keyboard", "platform", "setvar", + "kbfile", }; const char *mapcmd_names[MAPCMD_NUM] = { @@ -354,9 +355,16 @@ struct emulator_config *load_config_file(char *filename) { break; case CONFITEM_KEYBOARD: get_next_string(parse_line, cur_cmd, &str_pos, ' '); + cfg->keyboard_file = (char *)calloc(1, strlen(cur_cmd) + 1); cfg->keyboard_toggle_key = cur_cmd[0]; printf("Enabled keyboard event forwarding, toggle key %c.\n", cfg->keyboard_toggle_key); break; + case CONFITEM_KBFILE: + get_next_string(parse_line, cur_cmd, &str_pos, ' '); + cfg->keyboard_file = (char *)calloc(1, strlen(cur_cmd) + 1); + strcpy(cfg->keyboard_file, cur_cmd); + printf("Set keyboard event source file to %s.\n", cfg->keyboard_file); + break; case CONFITEM_PLATFORM: { char platform_name[128], platform_sub[128]; memset(platform_name, 0x00, 128); diff --git a/config_file/config_file.h b/config_file/config_file.h index 6880f0f..37cb0ce 100644 --- a/config_file/config_file.h +++ b/config_file/config_file.h @@ -39,6 +39,7 @@ typedef enum { CONFITEM_KEYBOARD, CONFITEM_PLATFORM, CONFITEM_SETVAR, + CONFITEM_KBFILE, CONFITEM_NUM, } config_items; @@ -64,7 +65,7 @@ struct emulator_config { struct platform_config *platform; - char *mouse_file; + char *mouse_file, *keyboard_file; char mouse_toggle_key, keyboard_toggle_key; unsigned char mouse_enabled, keyboard_enabled; diff --git a/default.cfg b/default.cfg index 56b55a9..73b0363 100644 --- a/default.cfg +++ b/default.cfg @@ -47,3 +47,7 @@ platform amiga #mouse /dev/input/mouse0 m # Forward keyboard events to host system, defaults to off unless toggle key is pressed, toggled off using F12. #keyboard k +# Select a specific filename for the keyboard event source. +# This is typically /dev/input/event1 or event0, but it may be event3 with for instance a wireless keyboard. +# Use ls /dev/input/event* to check which event files are available and try until you find the one that works. +#kbfile /dev/input/event1 diff --git a/emulator.c b/emulator.c index 214d310..167e014 100644 --- a/emulator.c +++ b/emulator.c @@ -458,7 +458,11 @@ int main(int argc, char *argv[]) { } } - keyboard_fd = open(keyboard_file, O_RDONLY | O_NONBLOCK); + if (cfg->keyboard_file) + keyboard_fd = open(cfg->keyboard_file, O_RDONLY | O_NONBLOCK); + else + keyboard_fd = open(keyboard_file, O_RDONLY | O_NONBLOCK); + if (keyboard_fd == -1) { printf("Failed to open keyboard event source.\n"); }