Skip to content

Commit

Permalink
macOS: Fix Ctrl keybinds not working (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
ileonte committed May 2, 2024
1 parent e8d927d commit 9dab567
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions modules/Input/macos.jai
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,12 @@ update_cocoa_window_events :: () {
array_add(*events_this_frame, event);
case NSEventTypeKeyDown;
keycode := NSEvent.keyCode(nsevent);
characters := NSEvent.characters(nsevent);
modifiers := NSEvent.modifierFlags(nsevent);
characters := NSEvent.characters(nsevent);
charslen := ifx characters then NSString.length(characters) else 0;
first := ifx charslen > 0 then NSString.characterAtIndex(characters, 0) else 128;
charactersNoMods := NSEvent.charactersIgnoringModifiers(nsevent);
charslenNoMods := ifx charactersNoMods then NSString.length(charactersNoMods) else 0;
first := ifx charslenNoMods > 0 then NSString.characterAtIndex(charactersNoMods, 0) else 128;

shift_state := (modifiers & NSEventModifierFlagShift) != 0;
ctrl_state := (modifiers & NSEventModifierFlagControl) != 0;
Expand Down Expand Up @@ -362,8 +364,10 @@ update_cocoa_window_events :: () {
// continue;
case NSEventTypeKeyUp;
keycode := NSEvent.keyCode(nsevent);
characters := NSEvent.characters(nsevent);
modifiers := NSEvent.modifierFlags(nsevent);
charactersNoMods := NSEvent.charactersIgnoringModifiers(nsevent);
charslenNoMods := ifx charactersNoMods then NSString.length(charactersNoMods) else 0;
first := ifx charslenNoMods > 0 then NSString.characterAtIndex(charactersNoMods, 0) else 128;

shift_state := (modifiers & NSEventModifierFlagShift) != 0;
ctrl_state := (modifiers & NSEventModifierFlagControl) != 0;
Expand All @@ -373,7 +377,7 @@ update_cocoa_window_events :: () {
event: Event;
event.type = .KEYBOARD;
event.key_pressed = 0;
event.key_code = get_key_code(keycode);
event.key_code = get_key_code(keycode, first);
event.packed = 0; // @Temporary: Unions not currently initialized.
event.shift_pressed = shift_state;
event.ctrl_pressed = ctrl_state;
Expand Down

0 comments on commit 9dab567

Please sign in to comment.