Skip to content

Commit 59a561a

Browse files
committed
gfxlib2/darwin: fix translate_key
1 parent e2b05aa commit 59a561a

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/gfxlib2/darwin/gfx_driver_opengl_cocoa.m

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -434,12 +434,13 @@ void fb_hCocoaWaitVSync() {
434434
dispatch_semaphore_wait(vsyncSema, DISPATCH_TIME_FOREVER);
435435
}
436436

437-
static inline int translate_key(unsigned char key, int scancode) {
438-
if (key == 0) {
439-
return scancode;
440-
} else {
441-
return fb_hScancodeToExtendedKey(scancode);
442-
}
437+
// TODO: Handle all extended keys properly
438+
static inline int translate_key(NSEvent* event, int scancode) {
439+
unsigned char key = [event charactersIgnoringModifiers].UTF8String[0];
440+
int extendedKey = fb_hScancodeToExtendedKey(scancode);
441+
if (extendedKey) return extendedKey;
442+
443+
return key;
443444
}
444445

445446
static void driver_poll_events() {
@@ -459,7 +460,7 @@ static void driver_poll_events() {
459460
e.scancode = fb_cocoakeycode_to_scancode[event.keyCode];
460461
__fb_gfx->key[e.scancode] = TRUE;
461462

462-
key = translate_key([event charactersIgnoringModifiers].UTF8String[0], e.scancode);
463+
key = translate_key(event, e.scancode);
463464
if (key) {
464465
fb_hPostKey(key);
465466
e.ascii = (key > 0 && key < 0xFF) ? key : 0;

src/rtlib/darwin/fb_private_scancodes_cocoa.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "../fb.h"
22

3-
static const int fb_cocoakeycode_to_scancode[] = {
3+
static const int fb_cocoakeycode_to_scancode[256] = {
44
[0x35] = SC_ESCAPE,
55
[0x7A] = SC_F1,
66
[0x78] = SC_F2,

0 commit comments

Comments
 (0)