ercanserteli / xercamods

Collection of Minecraft mods: XercaMod, Music Maker Mod and Joy of Painting
GNU General Public License v3.0
16 stars 19 forks source link

Music maker: Keyboard control on non-windows OSes is broken #77

Closed dithpri closed 1 year ago

dithpri commented 1 year ago

Trying to use the keyboard to control instruments on Linux doesn't work as intended (from searching the Discord server, at least one user complained of a similar issue on MacOS OS X). In my case, with a standard qwerty layout, "7" is the first key, and "r" is the last key of the octave. (so, the keys for playing the instrument are shifted backwards: 7, 8, 9, 0, -, =, <backspace>, <tab>, q, w, e, r). I am unsure whether those are universal for Linux or specific to my system/keyboard.

From my understanding, this bug comes from these two lines: https://github.com/ercanserteli/xercamods/blob/0137d42f91802288e322352629413737b946727e/XercaMusicMod/src/main/java/xerca/xercamusic/client/GuiInstrument.java#L255 https://github.com/ercanserteli/xercamods/blob/0137d42f91802288e322352629413737b946727e/XercaMusicMod/src/main/java/xerca/xercamusic/client/GuiInstrument.java#L287

GLFW Documentation: (emphasis mine)

The scancode is unique for every key, regardless of whether it has a key token. Scancodes are platform-specific but consistent over time, so keys will have different scancodes depending on the platform but they are safe to save to disk. You can query the scancode for any named key on the current platform with glfwGetKeyScancode.

Indeed, running xev reports the following:

KeyPress event, serial 34, synthetic NO, window 0x4400001,
    root 0x53f, subw 0x0, time 144219998, (1,376), root:(2090,422),
    state 0x0, keycode 16 (keysym 0x37, 7), same_screen YES,
    XLookupString gives 1 bytes: (37) "7"
    XmbLookupString gives 1 bytes: (37) "7"
    XFilterEvent returns: False

[snipped for brevity]

KeyPress event, serial 34, synthetic NO, window 0x4400001,
    root 0x53f, subw 0x0, time 144099122, (-74,368), root:(2015,414),
    state 0x0, keycode 27 (keysym 0x72, r), same_screen YES,
    XLookupString gives 1 bytes: (72) "r"
    XmbLookupString gives 1 bytes: (72) "r"
    XFilterEvent returns: False

That is, the code 16 corresponds to the key for "7" on a standard QWERTY keyboard, and 27 corresponds to "r" - which aligns with observations.

ercanserteli commented 1 year ago

Thank you for the explanation

ercanserteli commented 1 year ago

This should be fixed in 1676b4c4110f678b63f3ebc335b006df53f2f681 (1.19.2-1.1.0 and 1.19.3-1.1.0 on curseforge), but I can't test it on other platforms, so let me know if it doesn't work