Hi guys! I have a question about how LWJGL works
on OS X. I notice this:
If I'm using a QWERTY layout and I press Y, I get a keycode for Y in keyPressed.
If I'm using a QWERTZ layout and I press the same physical key, I get a keycode for Z in keyPressed.
I
like this behavior, but I am trying to understand how is is accomplished in LWJGL. It seems that LWJGL is using NSEvent keyCode:
https://github.com/LWJGL/lwjgl/blob/master/src/native/macosx/org_lwjgl_opengl_Display.m#L283When I use GLFW I see this:
If I'm using a QWERTY layout and I press Y, I get a keycode for Y in keyPressed.
If I'm using a QWERTZ layout and I press the same physical key, I get a keycode for
Y in keyPressed.
GLFW also uses NSEvent keyCode:
https://github.com/badlogic/jglfw/blob/master/jglfw/jni/glfw-3.0/src/cocoa_window.m#L464I'm confused, if both are just using the NSEvent keyCode, how is LWJGL respecting the user's keyboard locale while GLFW is not?
NSEvent reference:
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSEvent_Class/Reference/Reference.html#//apple_ref/occ/instm/NSEvent/keyCodeThis says: "The virtual key code. The returned value is hardware-independent." I take this to mean that the keyCode I get when I press Y with a QWERTY layout is the same code when the same physical key is pressed in the QWERTZ.
This text from HIToolbox/Events.h is even more explicit:
/*
* Summary:
* Virtual keycodes
*
* Discussion:
* These constants are the virtual keycodes defined originally in
* Inside Mac Volume V, pg. V-191. They identify physical keys on a
* keyboard. Those constants with "ANSI" in the name are labeled
* according to the key position on an ANSI-standard US keyboard.
* For example, kVK_ANSI_A indicates the virtual keycode for the key
* with the letter 'A' in the US keyboard layout. Other keyboard
* layouts may have the 'A' key label on a different physical key;
* in this case, pressing 'A' will generate a different virtual
* keycode.
*/
So it would seem that NSEvent keyCode is supposed to represent the physical key and does not take into account the user's keyboard locale. If this is the case, how does LWJGL respect the user's keyboard locale on OS X?