Use scan codes instead of key symbols
This commit is contained in:
parent
47d5b485d4
commit
8e61098fec
14
SDL/gui.c
14
SDL/gui.c
@ -362,10 +362,10 @@ void run_gui(bool is_running)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case SDL_KEYDOWN:
|
case SDL_KEYDOWN:
|
||||||
if (event.key.keysym.sym == SDLK_TAB) {
|
if (event.key.keysym.scancode == SDL_SCANCODE_TAB) {
|
||||||
cycle_scaling();
|
cycle_scaling();
|
||||||
}
|
}
|
||||||
else if (event.key.keysym.sym == SDLK_ESCAPE) {
|
else if (event.key.keysym.scancode == SDL_SCANCODE_ESCAPE) {
|
||||||
if (is_running) {
|
if (is_running) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -381,15 +381,15 @@ void run_gui(bool is_running)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (gui_state == SHOWING_MENU) {
|
if (gui_state == SHOWING_MENU) {
|
||||||
if (event.key.keysym.sym == SDLK_DOWN && current_menu[current_selection + 1].string) {
|
if (event.key.keysym.scancode == SDL_SCANCODE_DOWN && current_menu[current_selection + 1].string) {
|
||||||
current_selection++;
|
current_selection++;
|
||||||
should_render = true;
|
should_render = true;
|
||||||
}
|
}
|
||||||
else if (event.key.keysym.sym == SDLK_UP && current_selection) {
|
else if (event.key.keysym.scancode == SDL_SCANCODE_UP && current_selection) {
|
||||||
current_selection--;
|
current_selection--;
|
||||||
should_render = true;
|
should_render = true;
|
||||||
}
|
}
|
||||||
else if (event.key.keysym.sym == SDLK_RETURN) {
|
else if (event.key.keysym.scancode == SDL_SCANCODE_RETURN) {
|
||||||
if (current_menu[current_selection].handler) {
|
if (current_menu[current_selection].handler) {
|
||||||
current_menu[current_selection].handler();
|
current_menu[current_selection].handler();
|
||||||
if (pending_command) {
|
if (pending_command) {
|
||||||
@ -404,11 +404,11 @@ void run_gui(bool is_running)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (event.key.keysym.sym == SDLK_RIGHT && current_menu[current_selection].backwards_handler) {
|
else if (event.key.keysym.scancode == SDL_SCANCODE_RIGHT && current_menu[current_selection].backwards_handler) {
|
||||||
current_menu[current_selection].handler();
|
current_menu[current_selection].handler();
|
||||||
should_render = true;
|
should_render = true;
|
||||||
}
|
}
|
||||||
else if (event.key.keysym.sym == SDLK_LEFT && current_menu[current_selection].backwards_handler) {
|
else if (event.key.keysym.scancode == SDL_SCANCODE_LEFT && current_menu[current_selection].backwards_handler) {
|
||||||
current_menu[current_selection].backwards_handler();
|
current_menu[current_selection].backwards_handler();
|
||||||
should_render = true;
|
should_render = true;
|
||||||
}
|
}
|
||||||
|
40
SDL/main.c
40
SDL/main.c
@ -99,38 +99,38 @@ static void handle_events(GB_gameboy_t *gb)
|
|||||||
}
|
}
|
||||||
|
|
||||||
case SDL_KEYDOWN:
|
case SDL_KEYDOWN:
|
||||||
switch (event.key.keysym.sym) {
|
switch (event.key.keysym.scancode) {
|
||||||
case SDLK_ESCAPE:
|
case SDL_SCANCODE_ESCAPE:
|
||||||
run_gui(true);
|
run_gui(true);
|
||||||
GB_set_color_correction_mode(gb, color_correction_mode);
|
GB_set_color_correction_mode(gb, color_correction_mode);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDLK_c:
|
case SDL_SCANCODE_C:
|
||||||
if (event.type == SDL_KEYDOWN && (event.key.keysym.mod & KMOD_CTRL)) {
|
if (event.type == SDL_KEYDOWN && (event.key.keysym.mod & KMOD_CTRL)) {
|
||||||
GB_debugger_break(gb);
|
GB_debugger_break(gb);
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDLK_r:
|
case SDL_SCANCODE_R:
|
||||||
if (event.key.keysym.mod & MODIFIER) {
|
if (event.key.keysym.mod & MODIFIER) {
|
||||||
pending_command = GB_SDL_RESET_COMMAND;
|
pending_command = GB_SDL_RESET_COMMAND;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDLK_t:
|
case SDL_SCANCODE_T:
|
||||||
if (event.key.keysym.mod & MODIFIER) {
|
if (event.key.keysym.mod & MODIFIER) {
|
||||||
pending_command = GB_SDL_TOGGLE_MODEL_COMMAND;
|
pending_command = GB_SDL_TOGGLE_MODEL_COMMAND;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDLK_p:
|
case SDL_SCANCODE_P:
|
||||||
if (event.key.keysym.mod & MODIFIER) {
|
if (event.key.keysym.mod & MODIFIER) {
|
||||||
paused = !paused;
|
paused = !paused;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDLK_m:
|
case SDL_SCANCODE_M:
|
||||||
if (event.key.keysym.mod & MODIFIER) {
|
if (event.key.keysym.mod & MODIFIER) {
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
// Can't override CMD+M (Minimize) in SDL
|
// Can't override CMD+M (Minimize) in SDL
|
||||||
@ -142,15 +142,15 @@ static void handle_events(GB_gameboy_t *gb)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDLK_TAB:
|
case SDL_SCANCODE_TAB:
|
||||||
cycle_scaling();
|
cycle_scaling();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
/* Save states */
|
/* Save states */
|
||||||
if (event.key.keysym.sym >= SDLK_0 && event.key.keysym.sym <= SDLK_9) {
|
if (event.key.keysym.scancode >= SDL_SCANCODE_0 && event.key.keysym.scancode <= SDL_SCANCODE_9) {
|
||||||
if (event.key.keysym.mod & MODIFIER) {
|
if (event.key.keysym.mod & MODIFIER) {
|
||||||
command_parameter = event.key.keysym.sym - SDLK_0;
|
command_parameter = event.key.keysym.scancode - SDL_SCANCODE_0;
|
||||||
|
|
||||||
if (event.key.keysym.mod & KMOD_SHIFT) {
|
if (event.key.keysym.mod & KMOD_SHIFT) {
|
||||||
pending_command = GB_SDL_LOAD_STATE_COMMAND;
|
pending_command = GB_SDL_LOAD_STATE_COMMAND;
|
||||||
@ -163,32 +163,32 @@ static void handle_events(GB_gameboy_t *gb)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SDL_KEYUP: // Fallthrough
|
case SDL_KEYUP: // Fallthrough
|
||||||
switch (event.key.keysym.sym) {
|
switch (event.key.keysym.scancode) {
|
||||||
case SDLK_RIGHT:
|
case SDL_SCANCODE_RIGHT:
|
||||||
GB_set_key_state(gb, GB_KEY_RIGHT, event.type == SDL_KEYDOWN);
|
GB_set_key_state(gb, GB_KEY_RIGHT, event.type == SDL_KEYDOWN);
|
||||||
break;
|
break;
|
||||||
case SDLK_LEFT:
|
case SDL_SCANCODE_LEFT:
|
||||||
GB_set_key_state(gb, GB_KEY_LEFT, event.type == SDL_KEYDOWN);
|
GB_set_key_state(gb, GB_KEY_LEFT, event.type == SDL_KEYDOWN);
|
||||||
break;
|
break;
|
||||||
case SDLK_UP:
|
case SDL_SCANCODE_UP:
|
||||||
GB_set_key_state(gb, GB_KEY_UP, event.type == SDL_KEYDOWN);
|
GB_set_key_state(gb, GB_KEY_UP, event.type == SDL_KEYDOWN);
|
||||||
break;
|
break;
|
||||||
case SDLK_DOWN:
|
case SDL_SCANCODE_DOWN:
|
||||||
GB_set_key_state(gb, GB_KEY_DOWN, event.type == SDL_KEYDOWN);
|
GB_set_key_state(gb, GB_KEY_DOWN, event.type == SDL_KEYDOWN);
|
||||||
break;
|
break;
|
||||||
case SDLK_x:
|
case SDL_SCANCODE_X:
|
||||||
GB_set_key_state(gb, GB_KEY_A, event.type == SDL_KEYDOWN);
|
GB_set_key_state(gb, GB_KEY_A, event.type == SDL_KEYDOWN);
|
||||||
break;
|
break;
|
||||||
case SDLK_z:
|
case SDL_SCANCODE_Z:
|
||||||
GB_set_key_state(gb, GB_KEY_B, event.type == SDL_KEYDOWN);
|
GB_set_key_state(gb, GB_KEY_B, event.type == SDL_KEYDOWN);
|
||||||
break;
|
break;
|
||||||
case SDLK_BACKSPACE:
|
case SDL_SCANCODE_BACKSPACE:
|
||||||
GB_set_key_state(gb, GB_KEY_SELECT, event.type == SDL_KEYDOWN);
|
GB_set_key_state(gb, GB_KEY_SELECT, event.type == SDL_KEYDOWN);
|
||||||
break;
|
break;
|
||||||
case SDLK_RETURN:
|
case SDL_SCANCODE_RETURN:
|
||||||
GB_set_key_state(gb, GB_KEY_START, event.type == SDL_KEYDOWN);
|
GB_set_key_state(gb, GB_KEY_START, event.type == SDL_KEYDOWN);
|
||||||
break;
|
break;
|
||||||
case SDLK_SPACE:
|
case SDL_SCANCODE_SPACE:
|
||||||
GB_set_turbo_mode(gb, event.type == SDL_KEYDOWN, false);
|
GB_set_turbo_mode(gb, event.type == SDL_KEYDOWN, false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user