Add keyboard event source file setting to config-file

This commit is contained in:
beeanyew
2021-04-12 01:32:32 +02:00
parent 5aba9dec2b
commit 9240897dc2
4 changed files with 19 additions and 2 deletions

View File

@@ -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);

View File

@@ -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;

View File

@@ -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

View File

@@ -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");
}