comparison io.c @ 1254:d966298442d4

Implement keyboard capture functionality
author Michael Pavone <pavone@retrodev.com>
date Tue, 28 Feb 2017 23:50:12 -0800
parents c0120977eeea
children ccf5c02610c6
comparison
equal deleted inserted replaced
1253:2a6049dddab0 1254:d966298442d4
69 UI_SAVE_STATE, 69 UI_SAVE_STATE,
70 UI_SET_SPEED, 70 UI_SET_SPEED,
71 UI_NEXT_SPEED, 71 UI_NEXT_SPEED,
72 UI_PREV_SPEED, 72 UI_PREV_SPEED,
73 UI_RELEASE_MOUSE, 73 UI_RELEASE_MOUSE,
74 UI_TOGGLE_KEYBOARD_CAPTURE,
74 UI_TOGGLE_FULLSCREEN, 75 UI_TOGGLE_FULLSCREEN,
75 UI_SOFT_RESET, 76 UI_SOFT_RESET,
76 UI_EXIT 77 UI_EXIT
77 } ui_action; 78 } ui_action;
78 79
346 } 347 }
347 } 348 }
348 349
349 void handle_keydown(int keycode, uint8_t scancode) 350 void handle_keydown(int keycode, uint8_t scancode)
350 { 351 {
351 int bucket = keycode >> 15 & 0xFFFF; 352 if (current_io->keyboard_captured) {
352 if (!bindings[bucket]) { 353 store_key_event(scancode);
353 return; 354 } else {
354 } 355 int bucket = keycode >> 15 & 0xFFFF;
355 int idx = keycode & 0x7FFF; 356 if (!bindings[bucket]) {
356 keybinding * binding = bindings[bucket] + idx; 357 return;
357 handle_binding_down(binding); 358 }
358 store_key_event(scancode); 359 int idx = keycode & 0x7FFF;
360 keybinding * binding = bindings[bucket] + idx;
361 handle_binding_down(binding);
362 }
359 } 363 }
360 364
361 void handle_joydown(int joystick, int button) 365 void handle_joydown(int joystick, int button)
362 { 366 {
363 if (joystick >= MAX_JOYSTICKS || button >= joysticks[joystick].num_buttons) { 367 if (joystick >= MAX_JOYSTICKS || button >= joysticks[joystick].num_buttons) {
464 if (current_io->mouse_captured) { 468 if (current_io->mouse_captured) {
465 current_io->mouse_captured = 0; 469 current_io->mouse_captured = 0;
466 render_relative_mouse(0); 470 render_relative_mouse(0);
467 } 471 }
468 break; 472 break;
473 case UI_TOGGLE_KEYBOARD_CAPTURE:
474 current_io->keyboard_captured = !current_io->keyboard_captured;
475 break;
469 case UI_TOGGLE_FULLSCREEN: 476 case UI_TOGGLE_FULLSCREEN:
470 render_toggle_fullscreen(); 477 render_toggle_fullscreen();
471 break; 478 break;
472 case UI_SOFT_RESET: 479 case UI_SOFT_RESET:
473 current_system->soft_reset(current_system); 480 current_system->soft_reset(current_system);
481 } 488 }
482 489
483 void handle_keyup(int keycode, uint8_t scancode) 490 void handle_keyup(int keycode, uint8_t scancode)
484 { 491 {
485 int bucket = keycode >> 15 & 0xFFFF; 492 int bucket = keycode >> 15 & 0xFFFF;
486 if (!bindings[bucket]) {
487 return;
488 }
489 int idx = keycode & 0x7FFF; 493 int idx = keycode & 0x7FFF;
490 keybinding * binding = bindings[bucket] + idx; 494 keybinding * binding = bindings[bucket] ? bindings[bucket] + idx : NULL;
491 handle_binding_up(binding); 495 if (binding && (!current_io->keyboard_captured || (binding->bind_type == BIND_UI && binding->subtype_a == UI_TOGGLE_KEYBOARD_CAPTURE))) {
492 store_key_event(0xF000 | scancode); 496 handle_binding_up(binding);
497 } else {
498 store_key_event(0xF000 | scancode);
499 }
493 } 500 }
494 501
495 void handle_joyup(int joystick, int button) 502 void handle_joyup(int joystick, int button)
496 { 503 {
497 if (joystick >= MAX_JOYSTICKS || button >= joysticks[joystick].num_buttons) { 504 if (joystick >= MAX_JOYSTICKS || button >= joysticks[joystick].num_buttons) {
638 *ui_out = UI_NEXT_SPEED; 645 *ui_out = UI_NEXT_SPEED;
639 } else if(!strcmp(target + 3, "prev_speed")) { 646 } else if(!strcmp(target + 3, "prev_speed")) {
640 *ui_out = UI_PREV_SPEED; 647 *ui_out = UI_PREV_SPEED;
641 } else if(!strcmp(target + 3, "release_mouse")) { 648 } else if(!strcmp(target + 3, "release_mouse")) {
642 *ui_out = UI_RELEASE_MOUSE; 649 *ui_out = UI_RELEASE_MOUSE;
650 } else if(!strcmp(target + 3, "toggle_keyboard_captured")) {
651 *ui_out = UI_TOGGLE_KEYBOARD_CAPTURE;
643 } else if (!strcmp(target + 3, "toggle_fullscreen")) { 652 } else if (!strcmp(target + 3, "toggle_fullscreen")) {
644 *ui_out = UI_TOGGLE_FULLSCREEN; 653 *ui_out = UI_TOGGLE_FULLSCREEN;
645 } else if (!strcmp(target + 3, "soft_reset")) { 654 } else if (!strcmp(target + 3, "soft_reset")) {
646 *ui_out = UI_SOFT_RESET; 655 *ui_out = UI_SOFT_RESET;
647 } else if(!strcmp(target + 3, "exit")) { 656 } else if(!strcmp(target + 3, "exit")) {