The values of key identifiers in GDK depend on the language layout

I noticed that the constants in the GDK have a keyval value, which differ depending on the layout, unlike keycode.
I have come across many times that in GTK applications, shortcuts work only in the English layout, which is extremely inconvenient.

Here my little experiment on nim:

proc keyPressedCb(self: EventControllerKey, keyval: int, keycode: int, state: gdk4.ModifierType): bool =
  echo "keycode = ", keycode
  echo "keyval = ", keyval
  echo "gdk4.KEY_h = ", gdk4.KEY_h

And when pressed H key output is:

keycode = 43
keyval = 104
gdk4.KEY_h = 104

Maybe all constants should match keycode instead of keyvalue?

The keycode is the literal identifier of the key. In your example, the 43th key is the 6th key on the 2nd letter row.

You then use a keyboard layout (not a language) that maps each key code to a key value. For an English qwerty keyboard, keycode 43 is mapped to the letter “h”. If you use a Dvorak layout, this would be a “d”.

If you use keycode or keyval to identify a key should depend on whether you care about the physical location of the key on the keyboard or on the latter that will appear when you type it.

Hmm, and there is no universal way to catch a key regardless of the language(after all, in the dvorak layout, all key values in other languages also have a fixed position). I didn’t think about other layouts like drovak. I assume that other language layouts are used more often than alternative qwerty layouts.

Now it turns out that preference is given to other layouts and not languages, for everyone who uses GDK constants, and do not know about this feature.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.