Repository navigation
Alt, Shift and Caps Lock keys in Allegro on MacOSX problem #1679
Replies: 5 comments
|
To be clear, what Allegro version are you on? |
|
It's 5.2.11. |
|
https://en.wikipedia.org/wiki/Egg_of_Columbus |
|
In |
|
Actually I was debugging the behave of that UCKeyTranslate function checking flags in _al_osx_keyboard_handler, and didn't see anything not properly set, however the result was wrong using Alt (actually Option) key, both left and right, while on other keyboard layouts e.g. Greek, Ukrainian and Spanish, which I'm using in my program too, I didn't see any wrong. So my conclusion was it only happens when Option (Alt) key is involved, and I'm sure it's not due to interfering with some system shortcuts, basically those Option-a for ą, Option Shift for Ą or Option-c for ć Option Shift-c for Ć work perfectly fine in other programs including terminal, moreover, using Caps Lock it works too in terminal, with that difference, that Caps Lock is locking capitals, so Option-a with Cups Lock gives Ą and Option-Shift-a with Caps Lock give also capital Ą and - based on my experience for over 40 years of programming on many OSes should give lower case ą, because Caps Lock basically reverts action of Shift. I'm far away from the opinion that Apple is right of everything, so this is just small example. In some cases we use capitals nearly permanently (e.g. programming in Fortran). So if Caps Lock is activated, why I cannot use Shift once to change capital to lower case ? It's not only in case of diacritical signs, also simply key 'a' with Caps Lock gives A but Shit-a with Caps Lock also gives A what is frustrating, and very different comparing with rules established long time ago in such systems like Windows and Linux just to mention a few. That's why my workaround presented earlier actually correcting that problem too, by simple manipulation with flags: Cups Lock reverting the meaning of Shift, and it is not just for diacritics. Changing flags just before calling UCKeyTranslate has only the consequences while that function is called, so no impact on anything in the keyboard events buffer. I do not understand why that function does that mess, maybe somebody knows and is able to come with more elegant solution. Please. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Dear All,
Here is a problem with Alt, Shift and Caps Lock keys in Allegro on MacOSX.
In some keyboard layouts, diacritic characters are achieved by combination of latin letter and Alt key, for example in Polish (programmer's) keyboard, where "programmer's" is just a traditional term only due to commonly use of that layout in contrast to old typewriter layout (basically QUERTZ layout too instead of US-based QUERTY) which nobody is using. So it works perfectly fine on Linux and Windows, but it doesn't work at all on MacOSX.
Here is an example, actually log from examples/ex_keyboard_events.c
Focus on the main window (black) and press keys to see events.
KEY_DOWN code=001, char=' ' ( 0), modifiers=00000000, [A]
KEY_CHAR code=001, char='a' ( 97), modifiers=00000000, [A]
KEY_UP code=001, char=' ' ( 0), modifiers=00000000, [A]
KEY_DOWN code=226, char=' ' ( 0), modifiers=00000000, [CAPSLOCK]
KEY_UP code=226, char=' ' ( 0), modifiers=00000000, [CAPSLOCK]
KEY_DOWN code=001, char=' ' ( 0), modifiers=00000000, [A]
KEY_CHAR code=001, char='a' ( 97), modifiers=00000400, [A]
KEY_UP code=001, char=' ' ( 0), modifiers=00000000, [A]
KEY_DOWN code=226, char=' ' ( 0), modifiers=00000000, [CAPSLOCK]
KEY_UP code=226, char=' ' ( 0), modifiers=00000000, [CAPSLOCK]
KEY_DOWN code=219, char=' ' ( 0), modifiers=00000000, [ALT]
KEY_DOWN code=001, char=' ' ( 0), modifiers=00000000, [A]
KEY_CHAR code=001, char='ą' ( 261), modifiers=00000004, [A]
KEY_UP code=001, char=' ' ( 0), modifiers=00000000, [A]
KEY_UP code=219, char=' ' ( 0), modifiers=00000000, [ALT]
KEY_DOWN code=219, char=' ' ( 0), modifiers=00000000, [ALT]
KEY_DOWN code=215, char=' ' ( 0), modifiers=00000000, [LSHIFT]
KEY_DOWN code=001, char=' ' ( 0), modifiers=00000000, [A]
KEY_CHAR code=001, char='Ą' ( 260), modifiers=00000005, [A]
KEY_UP code=001, char=' ' ( 0), modifiers=00000000, [A]
KEY_UP code=215, char=' ' ( 0), modifiers=00000000, [LSHIFT]
KEY_UP code=219, char=' ' ( 0), modifiers=00000000, [ALT]
KEY_DOWN code=226, char=' ' ( 0), modifiers=00000000, [CAPSLOCK]
KEY_UP code=226, char=' ' ( 0), modifiers=00000000, [CAPSLOCK]
KEY_DOWN code=219, char=' ' ( 0), modifiers=00000000, [ALT]
KEY_DOWN code=001, char=' ' ( 0), modifiers=00000000, [A]
KEY_CHAR code=001, char='Ć' ( 262), modifiers=00000404, [A]
KEY_UP code=001, char=' ' ( 0), modifiers=00000000, [A]
KEY_UP code=219, char=' ' ( 0), modifiers=00000000, [ALT]
KEY_DOWN code=219, char=' ' ( 0), modifiers=00000000, [ALT]
KEY_DOWN code=215, char=' ' ( 0), modifiers=00000000, [LSHIFT]
KEY_DOWN code=001, char=' ' ( 0), modifiers=00000000, [A]
KEY_CHAR code=001, char='Ą' ( 260), modifiers=00000405, [A]
KEY_UP code=001, char=' ' ( 0), modifiers=00000000, [A]
KEY_UP code=215, char=' ' ( 0), modifiers=00000000, [LSHIFT]
KEY_UP code=219, char=' ' ( 0), modifiers=00000000, [ALT]
So what happened:
first pressed 'a', and got 'a'
Then activated Caps Lock, LED is on
pressed 'a' but got again lowercase 'a', what is wrong
Deactivated Caps Lock by pressing again (LED is off)
pressed Alt and keep pressing pressed 'a', and got 'ą'. Cool.
Then keeping Alt pressed pressed Shi9ft and simultanousy 'a' and got 'Ą'. Also cool, as should be.
Now activated Caps Lock again (LED is on) expecting, like always, Caps Lock always interfere with Shift, however this time Shif is "reversed".
So with activated Caps Lock pressed Alt and simultanously 'a' letter, but instead of expected "Ą" got "Ć" what is in unicode shifted by 2, however that shifting is not persistant, it depends of the letter, no idea why.
Now keep pressing Alt the Shift key was pressed and simultanously 'a' letter again, expecting this time 'ą' because with activated Caps Lock the Shift key should bring lowercase diacritic. But no, surspisingly I got uppercase 'Ą'.
With other diacritic characters is even worse, but I don't want to get you boring showing that. Anyway, for some reason, following my investigation:
if src/macosx/keybd.m
in function:
void _al_osx_keyboard_handler(int pressed, NSEvent event, ALLEGRO_DISPLAY dpy)
this function:
is doing wrong, no idea why. "unicode_string" is created wrongly.
UCKeyTranslate(::::::::::) is a standard Core - Unicode Utilities function and as is written in documantation:
"Converts a combination of a virtual key code, a modifier key state, and a dead-key state into a string of one or more Unicode characters.".
Cool, but in this case is doing wrong, however is the first time I got that problem, everywhere else is working fine including terminal.
So what is the solution to fix it? I came with Columbus's egg" solution, adding this piece of code front of that function:
///////// now with Columbus's egg solution
//by MAREK
if (modifier_key_state & 1) //Capslock is on
{
if (!(modifier_key_state & 2)) //there is no Shift
{
modifier_key_state &= ~1; // no Capslock anymore
modifier_key_state |= 2; //switch on Shift
}
else //Shift
{
modifier_key_state &= ~1; // no Capslock anymore
modifier_key_state &= ~2; // no Shift anymore
}
}
/////by MAREK
Here is an effect:
Focus on the main window (black) and press keys to see events.
KEY_DOWN code=001, char=' ' ( 0), modifiers=00000000, [A]
KEY_CHAR code=001, char='a' ( 97), modifiers=00000000, [A]
KEY_UP code=001, char=' ' ( 0), modifiers=00000000, [A]
KEY_DOWN code=226, char=' ' ( 0), modifiers=00000000, [CAPSLOCK]
KEY_UP code=226, char=' ' ( 0), modifiers=00000000, [CAPSLOCK]
KEY_DOWN code=001, char=' ' ( 0), modifiers=00000000, [A]
KEY_CHAR code=001, char='A' ( 65), modifiers=00000400, [A]
KEY_UP code=001, char=' ' ( 0), modifiers=00000000, [A]
KEY_DOWN code=226, char=' ' ( 0), modifiers=00000000, [CAPSLOCK]
KEY_UP code=226, char=' ' ( 0), modifiers=00000000, [CAPSLOCK]
KEY_DOWN code=219, char=' ' ( 0), modifiers=00000000, [ALT]
KEY_DOWN code=001, char=' ' ( 0), modifiers=00000000, [A]
KEY_CHAR code=001, char='ą' ( 261), modifiers=00000004, [A]
KEY_UP code=001, char=' ' ( 0), modifiers=00000000, [A]
KEY_UP code=219, char=' ' ( 0), modifiers=00000000, [ALT]
KEY_DOWN code=219, char=' ' ( 0), modifiers=00000000, [ALT]
KEY_DOWN code=215, char=' ' ( 0), modifiers=00000000, [LSHIFT]
KEY_DOWN code=001, char=' ' ( 0), modifiers=00000000, [A]
KEY_CHAR code=001, char='Ą' ( 260), modifiers=00000005, [A]
KEY_UP code=001, char=' ' ( 0), modifiers=00000000, [A]
KEY_UP code=215, char=' ' ( 0), modifiers=00000000, [LSHIFT]
KEY_UP code=219, char=' ' ( 0), modifiers=00000000, [ALT]
KEY_DOWN code=226, char=' ' ( 0), modifiers=00000000, [CAPSLOCK]
KEY_UP code=226, char=' ' ( 0), modifiers=00000000, [CAPSLOCK]
KEY_DOWN code=219, char=' ' ( 0), modifiers=00000000, [ALT]
KEY_DOWN code=001, char=' ' ( 0), modifiers=00000000, [A]
KEY_CHAR code=001, char='Ą' ( 260), modifiers=00000404, [A]
KEY_UP code=001, char=' ' ( 0), modifiers=00000000, [A]
KEY_UP code=219, char=' ' ( 0), modifiers=00000000, [ALT]
KEY_DOWN code=219, char=' ' ( 0), modifiers=00000000, [ALT]
KEY_DOWN code=215, char=' ' ( 0), modifiers=00000000, [LSHIFT]
KEY_DOWN code=001, char=' ' ( 0), modifiers=00000000, [A]
KEY_CHAR code=001, char='ą' ( 261), modifiers=00000405, [A]
KEY_UP code=001, char=' ' ( 0), modifiers=00000000, [A]
KEY_UP code=215, char=' ' ( 0), modifiers=00000000, [LSHIFT]
KEY_UP code=219, char=' ' ( 0), modifiers=00000000, [ALT]
so as expected.
Eventually, I was able, in my program, properly express what I want, in this example on the attached image the word "ciężarówka" which is using quite a number of diacritics, and is translated as "a truck".
Shall be my "Columbus's egg" solution inserted in official Allegro edition ? Probably not, because possibly it's too primitive and doesn't follow some stupid ideas by Apple e.g. to use Caps Lock as alternative switch key for keyboard layouts (instead of other key, like Control-Space bar to select the last input source, or Control-Option-Space bar to cycle through all your input sources but for permanent or more personalized hotkey, is possible to go to Apple menu > System Settings > Keyboard > Keyboard Shortcuts > Input Sources to customize these shortcuts or assign the Fn/Globe key to change input sources). But using Caps Lock for that is not great idea.
Anyway, byt Columbus's egg is better than nothing, isn't it ?
I hope for your comments.

Thanks and regards,
Marek
All reactions