diff --git a/src/cocoa_platform.h b/src/cocoa_platform.h index b422e13c..a31a8463 100644 --- a/src/cocoa_platform.h +++ b/src/cocoa_platform.h @@ -108,6 +108,7 @@ typedef struct _GLFWlibraryNS GLboolean cursorHidden; char* clipboardString; + char* keyName; _GLFWjoy joysticks[GLFW_JOYSTICK_LAST + 1]; } _GLFWlibraryNS; diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 454bd263..d118a717 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -1098,7 +1098,11 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode) const char* _glfwPlatformGetKeyName(int key) { - // First try to translate virtual key mac os x style + // free temp keyname + free(_glfw.ns.keyName); + _glfw.ns.keyName = 0; + + // Try to translate virtual key mac os x style UInt16 vKey = 0; switch(key) { @@ -1189,8 +1193,8 @@ const char* _glfwPlatformGetKeyName(int key) if (actualStringLength > 0 && status == noErr) { NSString* tempNS = [[NSString stringWithCharacters:unicodeString length:(NSUInteger)actualStringLength] uppercaseString]; - char* pTodoFree = strdup([tempNS UTF8String]); - return pTodoFree; + _glfw.ns.keyName = strdup([tempNS UTF8String]); + return _glfw.ns.keyName; } } }