Uinput Keyboard Events are Misinterpreted

I’m using KMonad to modify my keymap.

I reached out on the GNOME Terminal IRC channel initially, as that’s the first place I encountered the issue. Here is a slightly modified statement I used to introduce my issue there, including now some information recieved from zbrown.

GTK applications in general, but not all, listen to keyboard input through the window manager. I use KMonad, and I had to stop using Gnome Terminal because it will not properly listen to keyboard events that KMonad has generated.

I have it setup so a tap of the left or right shift keys emits ( and ) respectively, while holding them makes them operate normally. I have other modifications as well, but the extent of them is not relevant to the discussion unless I’m told otherwise. I can also upload my KMonad configuration to a pastebin if anyone wants to look at it.


It took me some time to determine how to do any debugging, but I now have some Gdk-messages about keyboard events and I also have some additional observations:

When I tap the left Shift key, its key-code (assumedly) surrounds the keycode for 9( key.

Gdk-Message: 17:27:13.331: keyboard press event, code 50, sym 65505, string , mods 0x11
Gdk-Message: 17:27:13.331: keyboard press event, code 18, sym 57, string 9, mods 0x10
Gdk-Message: 17:27:13.331: keyboard release event, code 18, sym 57, string 9, mods 0x10
Gdk-Message: 17:27:13.331: keyboard release event, code 50, sym 65505, string , mods 0x10

When I press and release the 9(, or 0) keys alone, they emit, respectively:

  • Gdk-Message: 17:32:56.041: keyboard press event, code 18, sym 57, string 9, mods 0x10 Gdk-Message: 17:32:56.111: keyboard release event, code 18, sym 57, string 9, mods 0x10

  • Gdk-Message: 17:32:56.864: keyboard press event, code 19, sym 48, string 0, mods 0x10 Gdk-Message: 17:32:56.968: keyboard release event, code 19, sym 48, string 0, mods 0x10

If I hold the right shift key (ie, normal shift) and then press the left shift key I can produce a ( in Gedit, or other GTK apps that aren’t respective KMonad. Interestingly, the sequence of keypress events that are logged are reversed from above:

Gdk-Message: 17:35:32.223: keyboard release event, code 18, sym 40, string (, mods 0x11
Gdk-Message: 17:35:32.223: keyboard release event, code 50, sym 65505, string , mods 0x10
Gdk-Message: 17:35:32.832: keyboard press event, code 50, sym 65505, string , mods 0x11
Gdk-Message: 17:35:32.832: keyboard press event, code 18, sym 40, string (, mods 0x11

So, the symbol and string representation of the 9( key has changed, but nothing about the left shift key itself has changed. Strangely, yes, the right shift key is not found in this sequence at all! To be explicity, here is what happens when I tap the right shift, so you can see that its scan code is 62 and does not appear in the above sequence:

Gdk-Message: 17:47:09.803: keyboard press event, code 62, sym 65506, string , mods 0x11
Gdk-Message: 17:47:09.803: keyboard press event, code 19, sym 48, string 0, mods 0x10
Gdk-Message: 17:47:09.803: keyboard release event, code 19, sym 48, string 0, mods 0x10
Gdk-Message: 17:47:09.803: keyboard release event, code 62, sym 65506, string , mods 0x10


To make matters most interesting, the GTK Inspector for Gedit that will open with GDK_DEBUG=interactive gedit does not itself disrespect KMonad. If I press Ctrl-f to begin searching and then tap the left shift key, what is produced is ( as expected. Gedit, which is being debugged by that introspector does not produce the same output.

Any help would be appreciated.

I have found that there is a difference between GTK3 and GTK4 applications. The Gtk Inspector for GTK3 applications properly interprets the keyboard events, while in GTK4 applications the keyboard events are properly interpreted.

This was found in multiple applications.
GTK4:

  • Text Editor 42.alpha1 (42.alpha1)
  • Shortwave 2.0.1-stable

GTK3:

  • Text Editor 41.alpha