Skip to content

Commit d95ed23

Browse files
committed
macos: more attempts at correct modifier key handling
Fixes #13880
1 parent e69ee5a commit d95ed23

2 files changed

Lines changed: 23 additions & 7 deletions

File tree

input/drivers/cocoa_input.m

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ void apple_input_keyboard_event(bool down,
310310
settings_t *settings = config_get_ptr();
311311
bool keyboard_gamepad_enable = settings->bools.input_keyboard_gamepad_enable;
312312
bool small_keyboard_enable = settings->bools.input_small_keyboard_enable;
313+
unsigned original_code = code;
313314

314315
if (keyboard_gamepad_enable)
315316
{
@@ -326,10 +327,15 @@ void apple_input_keyboard_event(bool down,
326327
character = 0;
327328
}
328329

330+
/* Update state for both original and translated keys if different */
331+
if (original_code > 0 && original_code < MAX_KEYS)
332+
apple_key_state[original_code] = down;
333+
329334
if (code == 0 || code >= MAX_KEYS)
330335
return;
331336

332-
apple_key_state[code] = down;
337+
if (code != original_code)
338+
apple_key_state[code] = down;
333339

334340
input_keyboard_event(down,
335341
input_keymaps_translate_keysym_to_rk(code),
@@ -441,7 +447,7 @@ static int16_t cocoa_lightgun_aiming_state(
441447
int16_t res_y = 0;
442448
int16_t res_screen_x = 0;
443449
int16_t res_screen_y = 0;
444-
450+
445451
int16_t x = apple->window_pos_x;
446452
int16_t y = apple->window_pos_y;
447453

@@ -679,7 +685,7 @@ static int16_t cocoa_input_state(
679685
float axis_threshold = joypad_info->axis_threshold;
680686
const uint32_t joykey = (bind_joykey != NO_BTN) ? bind_joykey : autobind_joykey;
681687
const uint32_t joyaxis = (bind_joyaxis != AXIS_NONE) ? bind_joyaxis : autobind_joyaxis;
682-
688+
683689
if (binds[port][new_id].valid)
684690
{
685691
if ((uint16_t)joykey != NO_BTN && joypad->button(joyport, (uint16_t)joykey))

ui/drivers/ui_cocoa.m

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,13 +449,23 @@ - (void)sendEvent:(NSEvent *)event {
449449
{
450450
static NSUInteger old_flags = 0;
451451
NSUInteger new_flags = event.modifierFlags;
452-
bool down = (new_flags & old_flags) == old_flags;
452+
NSUInteger changed_flags = new_flags ^ old_flags;
453453
uint16_t keycode = event.keyCode;
454+
bool down = false;
454455

455-
old_flags = new_flags;
456+
/* Determine if the changed modifier is being pressed or released
457+
* by checking if it's set in the new flags */
458+
if (changed_flags != 0)
459+
{
460+
/* Find which specific modifier changed and its new state */
461+
NSUInteger single_change = changed_flags & -changed_flags; /* Isolate rightmost bit */
462+
down = (new_flags & single_change) != 0;
463+
464+
apple_input_keyboard_event(down, keycode,
465+
0, (uint32_t)new_flags, RETRO_DEVICE_KEYBOARD);
466+
}
456467

457-
apple_input_keyboard_event(down, keycode,
458-
0, (uint32_t)new_flags, RETRO_DEVICE_KEYBOARD);
468+
old_flags = new_flags;
459469
}
460470
break;
461471
case NSEventTypeMouseMoved:

0 commit comments

Comments
 (0)