changeset 1254:d966298442d4

Implement keyboard capture functionality
author Michael Pavone <pavone@retrodev.com>
date Tue, 28 Feb 2017 23:50:12 -0800
parents 2a6049dddab0
children 6370b80491c7
files default.cfg io.c io.h
diffstat 3 files changed, 24 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/default.cfg	Tue Feb 28 21:59:58 2017 -0800
+++ b/default.cfg	Tue Feb 28 23:50:12 2017 -0800
@@ -32,6 +32,7 @@
 		- ui.prev_speed
 		f11 ui.toggle_fullscreen
 		tab ui.soft_reset
+		rctrl ui.toggle_keyboard_captured
 	}
 	pads {
 		0 {
--- a/io.c	Tue Feb 28 21:59:58 2017 -0800
+++ b/io.c	Tue Feb 28 23:50:12 2017 -0800
@@ -71,6 +71,7 @@
 	UI_NEXT_SPEED,
 	UI_PREV_SPEED,
 	UI_RELEASE_MOUSE,
+	UI_TOGGLE_KEYBOARD_CAPTURE,
 	UI_TOGGLE_FULLSCREEN,
 	UI_SOFT_RESET,
 	UI_EXIT
@@ -348,14 +349,17 @@
 
 void handle_keydown(int keycode, uint8_t scancode)
 {
-	int bucket = keycode >> 15 & 0xFFFF;
-	if (!bindings[bucket]) {
-		return;
+	if (current_io->keyboard_captured) {
+		store_key_event(scancode);
+	} else {
+		int bucket = keycode >> 15 & 0xFFFF;
+		if (!bindings[bucket]) {
+			return;
+		}
+		int idx = keycode & 0x7FFF;
+		keybinding * binding = bindings[bucket] + idx;
+		handle_binding_down(binding);
 	}
-	int idx = keycode & 0x7FFF;
-	keybinding * binding = bindings[bucket] + idx;
-	handle_binding_down(binding);
-	store_key_event(scancode);
 }
 
 void handle_joydown(int joystick, int button)
@@ -466,6 +470,9 @@
 				render_relative_mouse(0);
 			}
 			break;
+		case UI_TOGGLE_KEYBOARD_CAPTURE:
+			current_io->keyboard_captured = !current_io->keyboard_captured;
+			break;
 		case UI_TOGGLE_FULLSCREEN:
 			render_toggle_fullscreen();
 			break;
@@ -483,13 +490,13 @@
 void handle_keyup(int keycode, uint8_t scancode)
 {
 	int bucket = keycode >> 15 & 0xFFFF;
-	if (!bindings[bucket]) {
-		return;
+	int idx = keycode & 0x7FFF;
+	keybinding * binding = bindings[bucket] ? bindings[bucket] + idx : NULL;
+	if (binding && (!current_io->keyboard_captured || (binding->bind_type == BIND_UI && binding->subtype_a == UI_TOGGLE_KEYBOARD_CAPTURE))) {
+		handle_binding_up(binding);
+	} else {
+		store_key_event(0xF000 | scancode);
 	}
-	int idx = keycode & 0x7FFF;
-	keybinding * binding = bindings[bucket] + idx;
-	handle_binding_up(binding);
-	store_key_event(0xF000 | scancode);
 }
 
 void handle_joyup(int joystick, int button)
@@ -640,6 +647,8 @@
 			*ui_out = UI_PREV_SPEED;
 		} else if(!strcmp(target + 3, "release_mouse")) {
 			*ui_out = UI_RELEASE_MOUSE;
+		} else if(!strcmp(target + 3, "toggle_keyboard_captured")) {
+			*ui_out = UI_TOGGLE_KEYBOARD_CAPTURE;
 		} else if (!strcmp(target + 3, "toggle_fullscreen")) {
 			*ui_out = UI_TOGGLE_FULLSCREEN;
 		} else if (!strcmp(target + 3, "soft_reset")) {
--- a/io.h	Tue Feb 28 21:59:58 2017 -0800
+++ b/io.h	Tue Feb 28 23:50:12 2017 -0800
@@ -70,6 +70,7 @@
 	io_port	ports[3];
 	uint8_t mouse_mode;
 	uint8_t mouse_captured;
+	uint8_t keyboard_captured;
 } sega_io;
 
 #define GAMEPAD_TH0 0