dalhai wrote on Friday, April 03, 2015:
Hi guys,
First of all to the devs, thanks for your effort on GLFW, the library is amazing.
Situation
For my game, I want to provide users with the option to reassign key bindings from an option screen. My current approach is to store the key code mappings in an XML file, which I load when the game starts.
Problem
It would be nice to show users the symbols the respective keys produce instead of a physical key identifier. In the options menu, the user should be able to specify for an action, let’s call it “Jump”, a key that is supposed to trigger that action. However, instead of displaying
"Jump is triggered by <SOME_KEY>"
where <SOME_KEY> is a predefined name for the key code, I want to display the actual unicode output generated by the key. For example:
"Jump is triggered by ‘Ü’"
where ‘Ü’ would be the unicode output generated by pressing the specified key with the current layout.
Now, as far as I see, glfw internally translates the key code to unicode characters using the system specific methods. Is there any way for us to use these translations ourselves?
Goal
What I would do, given methods to convert key codes to unicode output:
- Load the action to key code mapping from the user preferences or a default configuration if the game is started for the first time.
- When in the key reassignment menu, translate the key codes to the corresponding unicode produced by the current keyboard layout and display them.
Is there anything like that provided by glfw, given that these translations are done internally anyway? If yes, and I just did not see it when looking for it, is there by any chance also a callback to react to keyboard layout changes?
If no, has anyone else implemented a platform independent solution for the problem which I could be using? Or is my only option to implement the functionality myself using the low level methods provided by each system if I do not want to stray away from glfw?
Thanks in advance for your help!