Getting the real keycode on OSX


#1

Hi,

In my app users are allowed to use combination of Shift+Numbers to do some stuff. Everything works fine when the users use Shif + numpad keys. The problem shows itself when the users use the number keys (the ones below function keys). On Windows and in KeyPressed function it always give me the same key code with or without Shift. For example for number 1 it always gives keyCode = 49 no matter if Shift is pressed or not. On OSX, though, it gives the character code of the generated key for example Shift+1 on a German layout gives keyCode = 33 which is "!" sign. It makes the code Keyboard Layout dependant.

Is there a way of accessing the real KeyCode of the NSEvent on OSX? It seems all we get is the key code for the charachter represantation.

 

Thanks 


#2

Hi ehsanen,

This issue should now be fixed in the latest tip.

The fix requires the TextInputServices API which is technically part of Carbon. TextInputServices is heavily used by Cocoa internally (even on 64-bit) so I doubt that this will be deprecated anytime soon. Nevertheless, you need to define JUCE_SUPPORT_CARBON=1 to enable this fix.

You can do this, for example, by defining this in the "Extra Preprocessor Definitions" field in the Introjucer when clicking on the "Xcode (MacOSX)" Target. 

Does this fix your problem?

Thanks for reporting!

Fabian


#3

Yes that solved the problem, thank you for the quick reply.