fixed swapping opt and cmd key if keycode file is used

This commit is contained in:
kanjitalk755 2021-02-07 09:34:22 +09:00
parent 89e8a05815
commit fbddf063cb
1 changed files with 16 additions and 8 deletions

View File

@ -2053,13 +2053,19 @@ static bool is_hotkey_down(SDL_Keysym const & ks)
(cmd_down || (ks.mod & KMOD_GUI) || !(hotkey & 4));
}
static bool swap_opt_cmd() {
static int modify_opt_cmd(int code) {
static bool f, c;
if (!f) {
f = true;
c = PrefsFindBool("swap_opt_cmd");
}
return c;
if (c) {
switch (code) {
case 0x37: return 0x3a;
case 0x3a: return 0x37;
}
}
return code;
}
/*
@ -2136,8 +2142,8 @@ static int kc_decode(SDL_Keysym const & ks, bool key_down)
case SDLK_RCTRL: return 0x36;
case SDLK_LSHIFT: return 0x38;
case SDLK_RSHIFT: return 0x38;
case SDLK_LALT: case SDLK_RALT: return swap_opt_cmd() ? 0x37 : 0x3a;
case SDLK_LGUI: case SDLK_RGUI: return swap_opt_cmd() ? 0x3a : 0x37;
case SDLK_LALT: case SDLK_RALT: return 0x3a;
case SDLK_LGUI: case SDLK_RGUI: return 0x37;
case SDLK_MENU: return 0x32;
case SDLK_CAPSLOCK: return 0x39;
case SDLK_NUMLOCKCLEAR: return 0x47;
@ -2348,6 +2354,7 @@ static void handle_events(void)
code = event2keycode(event.key, true);
if (code >= 0) {
if (!emul_suspended) {
code = modify_opt_cmd(code);
#ifdef __MACOSX__
ADBKeyDown(code);
#else
@ -2358,9 +2365,9 @@ static void handle_events(void)
#endif
if (code == 0x36)
ctrl_down = true;
if (code == (swap_opt_cmd() ? 0x37 : 0x3a))
if (code == 0x3a)
opt_down = true;
if (code == (swap_opt_cmd() ? 0x3a : 0x37))
if (code == 0x37)
cmd_down = true;
} else {
@ -2377,6 +2384,7 @@ static void handle_events(void)
if (code == CODE_INVALID)
code = event2keycode(event.key, false);
if (code >= 0) {
code = modify_opt_cmd(code);
#ifdef __MACOSX__
ADBKeyUp(code);
#else
@ -2385,9 +2393,9 @@ static void handle_events(void)
#endif
if (code == 0x36)
ctrl_down = false;
if (code == (swap_opt_cmd() ? 0x37 : 0x3a))
if (code == 0x3a)
opt_down = false;
if (code == (swap_opt_cmd() ? 0x3a : 0x37))
if (code == 0x37)
cmd_down = false;
}
break;