Skip to content

Commit a7383ab

Browse files
committed
Fix GL Error 65540: Invalid scancode 0
1 parent a816470 commit a7383ab

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/main/kotlin/com/lambda/gui/widgets/KeybindWidget.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ class KeybindWidget(
5959

6060
fun ImGuiBuilder.build() {
6161
val current = valueGetter()
62-
val translated = KeyCode.virtualMapUS(current.keyCode, 0)
62+
val scancode = GLFW.glfwGetKeyScancode(current.keyCode)
63+
val translated = KeyCode.virtualMapUS(current.keyCode, scancode)
6364
val preview = if (listening) "$label: Press any key…" else "$label: ${translated.prettyDisplay()}"
6465

6566
if (listening) {
@@ -102,7 +103,15 @@ class KeybindWidget(
102103

103104
private fun KeyCode.prettyDisplay(): String {
104105
if (this == KeyCode.UNBOUND) return "Unbound"
105-
val name = GLFW.glfwGetKeyName(keyCode, 0)
106-
return name?.ifBlank { null }?.uppercase() ?: this.name
106+
if (keyCode == GLFW.GLFW_KEY_UNKNOWN) return name
107+
108+
val scancode = GLFW.glfwGetKeyScancode(keyCode)
109+
val nameFromGlfw = if (scancode != 0) {
110+
GLFW.glfwGetKeyName(GLFW.GLFW_KEY_UNKNOWN, scancode)
111+
} else {
112+
GLFW.glfwGetKeyName(keyCode, 0)
113+
}
114+
115+
return nameFromGlfw?.takeIf { it.isNotBlank() }?.uppercase() ?: name
107116
}
108117
}

0 commit comments

Comments
 (0)