i am developing a Terminal Emulator in C++ chose OpenGL for rendering for being most platform independant. Therefore I also chose GLFW because it is meant to be everywhere (*).
I need to respect users input mappings (such as different keyboard layouts), but also need to know when Control, Alt, or Meta was pressed. As I am translating the GLFW input events into Virtual Terminal input control sequences.
glfwSetKeyCallback provides me access to the modifiers, but no mappings, whereas glfwSetCharCallback provides me the right character input but no modifiers. This seams to be mutually exclusive.
What I tried is to just register both callbacks - as it seems that key callback is always invoked first and char callback always invoked second - and translate the input event in the char callback only if it wasn’t processed in the key callback yet.
However sometimes the char callback is not invoked at all but the key callback only. For example in en_US keyboard layout, pressing Ctrl+[, I can grab everything as expected.
Now, when on keyboard layout de_DE, in order to generate a Ctrl+[, you also need to press AltGr, so Ctrl+Alt(Gr)+[ (
[ is on the physical key
This info can be grabbed via key callback, but not via char callback, and the char callback isn’t even invoked for that (because Ctrl was pressed, too?)
How can I untangle this situation and grab the proper char text data while also knowing about modifiers (that were not required to contruct the letters, such as
[ in my case - the Ctrl).
edit: I just realized there is a
glfwSetCharModsCallback API function, but it’s marked deprecated and it’s not working for the Ctrl+[ on german keyboard (de_DE) layout case. That is, in order to emit a
[ in de_DE you must press AltGr+8, and glfw does that fine. But as soon as you ALSO press the control key, the symbol
8 instead of
[ is being sent, which makes using the callback useless (as it just seems to mirror what key callback would have known too). Is this a bug in glfwSetCharModsCallback’s, and what’s the reason in dropping this API in the first place?
Many thanks in advance,
(*) Except WindowsStore.