Skip to content

Commit 774a598

Browse files
SiegeLordExSiegeLord
authored andcommitted
Fix a few more situations with the new MacOS key input.
- Invalid dead key combos now return the last-pressed key, rather than the character represention of the dead key - Command + key now returns key, rather than ^key (cherry picked from commit 0e05a3b)
1 parent a124e90 commit 774a598

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/macosx/keybd.m

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,18 +296,29 @@ void _al_osx_keyboard_handler(int pressed, NSEvent *event, ALLEGRO_DISPLAY* dpy)
296296
4,
297297
&unicode_length,
298298
unicode_string);
299-
300299
if (unicode_length > 0) {
301300
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));
303308
if (unichar < 0)
304309
unichar = 0;
305310
/* 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)
307312
unichar = '\r';
313+
/* This is here to override the Ctrl/Cmd fixes for backspace. */
314+
else if (scancode == ALLEGRO_KEY_BACKSPACE)
315+
unichar = '\b';
308316
/* For some reason, Ctrl-<key> sends capital version of the character,
309317
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)
311322
unichar = character;
312323
al_ustr_free(ustr);
313324
}
@@ -317,6 +328,7 @@ void _al_osx_keyboard_handler(int pressed, NSEvent *event, ALLEGRO_DISPLAY* dpy)
317328
unichar = character;
318329

319330
/* Apple maps function, arrow, and other keys to Unicode points.
331+
https://www.unicode.org/Public/MAPPINGS/VENDORS/APPLE/CORPCHAR.TXT
320332
We want to generate CHAR events for them, so we'll override the translation logic.
321333
_handle_key_press will set the unichar back to 0 for these keys. */
322334
if (character >= 0xF700 && character <= 0xF747) {

0 commit comments

Comments
 (0)