Browse Source

GlfwKeyInput: handle GLFW_KEY_UNKNOWN return by fromJmeKeyCode() (#1638)

Stephen Gold 3 years ago
parent
commit
de4de00861
1 changed files with 13 additions and 2 deletions
  1. 13 2
      jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwKeyInput.java

+ 13 - 2
jme3-lwjgl3/src/main/java/com/jme3/input/lwjgl/GlfwKeyInput.java

@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009-2012 jMonkeyEngine
+ * Copyright (c) 2009-2021 jMonkeyEngine
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -109,10 +109,21 @@ public class GlfwKeyInput implements KeyInput {
         charCallback.close();
     }
 
+    /**
+     * Determine the name of the specified key in the current system language.
+     *
+     * @param jmeKey the keycode from {@link com.jme3.input.KeyInput}
+     * @return the name of the key, or null if unknown
+     */
     @Override
     public String getKeyName(int jmeKey) {
         int glfwKey = GlfwKeyMap.fromJmeKeyCode(jmeKey);
-        return glfwGetKeyName(glfwKey, 0);
+        if (glfwKey == GLFW_KEY_UNKNOWN) {
+            return null;
+        }
+
+        String result = glfwGetKeyName(glfwKey, 0);
+        return result;
     }
 
     private void initCallbacks() {