@@ -296,18 +296,29 @@ void _al_osx_keyboard_handler(int pressed, NSEvent *event, ALLEGRO_DISPLAY* dpy)
296
296
4 ,
297
297
&unicode_length,
298
298
unicode_string);
299
-
300
299
if (unicode_length > 0 ) {
301
300
ALLEGRO_USTR *ustr = al_ustr_new_from_utf16 (unicode_string);
302
- unichar = al_ustr_get (ustr, 0 );
301
+ /* TODO: Possibly add an option to emit multiple events here.
302
+ * At the moment, we take the last key, because when an invalid
303
+ * dead key combination is entered, unicode string contains a character
304
+ * representaiton of the dead key + the last pressed key.
305
+ * We opt to return the last pressed key.
306
+ */
307
+ unichar = al_ustr_get (ustr, al_ustr_offset (ustr, (int )unicode_length - 1 ));
303
308
if (unichar < 0 )
304
309
unichar = 0 ;
305
310
/* For some reason, pad enter sends a ^C. */
306
- if (scancode == ALLEGRO_KEY_PAD_ENTER && unichar == 3 )
311
+ else if (scancode == ALLEGRO_KEY_PAD_ENTER && unichar == 3 )
307
312
unichar = ' \r ' ;
313
+ /* This is here to override the Ctrl/Cmd fixes for backspace. */
314
+ else if (scancode == ALLEGRO_KEY_BACKSPACE)
315
+ unichar = ' \b ' ;
308
316
/* For some reason, Ctrl-<key> sends capital version of the character,
309
317
and not the correct invisible character. */
310
- if (key_shifts & ALLEGRO_KEYMOD_CTRL)
318
+ else if (key_shifts & ALLEGRO_KEYMOD_CTRL)
319
+ unichar = character;
320
+ /* For some reason, Cmd-<key> converts characters to Ctrl-<key>. */
321
+ else if (key_shifts & ALLEGRO_KEYMOD_COMMAND)
311
322
unichar = character;
312
323
al_ustr_free (ustr);
313
324
}
@@ -317,6 +328,7 @@ void _al_osx_keyboard_handler(int pressed, NSEvent *event, ALLEGRO_DISPLAY* dpy)
317
328
unichar = character;
318
329
319
330
/* Apple maps function, arrow, and other keys to Unicode points.
331
+ https://www.unicode.org/Public/MAPPINGS/VENDORS/APPLE/CORPCHAR.TXT
320
332
We want to generate CHAR events for them, so we'll override the translation logic.
321
333
_handle_key_press will set the unichar back to 0 for these keys. */
322
334
if (character >= 0xF700 && character <= 0xF747 ) {
0 commit comments