tolga9009 / sidewinderd

Linux support for Microsoft SideWinder X4 / X6 and Logitech G103 / G105 / G710+.

Home Page:http://cevel.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Remapping keys in X11

The-Plottwist opened this issue · comments

Edit after a YEAR: Solution was just SHIFT + F1-F12. See this comment for details.

Keyboard management in X11 is a mess. There are two reasons for this:

  • X server uses a two layered event handling, which consists of keysym and X-key code. keysym is the actual representation of a given letter. On the other hand, X-key code, as you might guess, is a predefined list of key codes which varies on a given X server implementation and on a physical keyboard. Thus, there isn't any standard for which key ties to which unlike as in Linux Kernel, or at least I couldn't found one. (For more information, please visit: VMware)
  • X server currently supports only one-byte values, which means 255 different key codes.

The problem I had with that I can't assign my G keys through F13-F18 as mentioned in #35, as F13-F18 keys aren't supported in X-key code even though they had defined in keysymdef.h see below.

Another problem that may arise is with the key codes bigger than one-byte, which are generally media controls. They are completely ignored when pressed.

Both of the problems can be solved by binding them to the keys in the 0-255 range.

To view your X-key codes, use: xmodmap -pke
To view the key code of which key you press, use: xev | awk -F'[ )]+' '/^KeyPress/ { a[NR+2] } NR in a { printf "%-3s %s\n", $5, $8 }' (from archwiki)

For the keys, I used XF86Launch1 - XF86Launch6, instead of F13-F18 and then configured my programs according to these keys.

  • Assigning G keys: In my X server configuration, my key codes for XF86Launch1 - XF86Launch6 are respectively: 156, 157, 210, 211, 192, 193. I don't know why but to be able to define them as mentioned in #35 , I had to decrease them by eight. So for example, my s1.xml key macro has the contents of:
<Macro>
    <KeyBoardEvent Down="true">148</KeyBoardEvent>
    <KeyBoardEvent Down="false">148</KeyBoardEvent>
</Macro>
  • Assigning keys that are bigger than one-byte: You can follow this guide on archwiki.

Hope this helps @tolga9009, especially when writing a GUI in the future.

Cheers.

Yesterday, I stumbled upon this site "key naming" and I probably have found a solution.

Let's clarify some points.
First of all, Xorg does support "F13 - F18 F24" and key definitions can be found in keysymdef.h and multimedia key definitions in XF86keysym.h.

Secondly, the keymapping I have showed earlier is just a one way to do it.
So, here are the other two:

  1. Console only: Use loadkeys. [Console Keyboard]
  2. Xorg (X11): Use xmodmap. [Xorg Keymapping]

To achieve what I wanted, I needed to configure X11. Therefore I used [Xorg Keymapping].

Here are the steps that I have followed:

  • First, for not to mess up your current configuration, find empty key codes with xmodmap -pke | grep -i "=\$"
  • Then, open up a new (or existing) ~/.xmodmaprc file and type keycode EMPTY_KEYCODE_HERE = YOUR_KEY_HERE (key values are case sensitive and no need for XK_ prefix)
  • Run xmodmap ~/.xmodmaprc to asssign them right away.
  • Make them permanent by echo 'xmodmap ~/.xmodmaprc' >> ~/.xinitrc
  • Lastly, in your macro configuration assign your keys (default macros are in ~/.local/share/sidewinderd/profile_1/). But beware, you have to decrease your key codes by eight.

For example:

~/.xinitrc
xmodmap ~/.xmodmaprc
~/.xmodmaprc
keycode 103 = F13
keycode 120 = F14
...
~/.local/share/sidewinderd/profile_1/s1.xml
<Macro>
    <KeyBoardEvent Down="true">95</KeyBoardEvent>
    <KeyBoardEvent Down="false">95</KeyBoardEvent>
</Macro>
~/.local/share/sidewinderd/profile_1/s2.xml
<Macro>
    <KeyBoardEvent Down="true">112</KeyBoardEvent>
    <KeyBoardEvent Down="false">112</KeyBoardEvent>
</Macro>

In conclusion, you can now assign shortcuts through F13-F18, which was my initial goal for my additional Text Editor shortcuts.
Future Edit: Freaking text editor does not recognize X11's "F13-F18". Amazing...

Well, with much frustration and work done after achieving nothing, the fucking solution was so simple:
SHIFT + F1...F12

When combined with Shift, Ctrl and Alt and Windows it gave me 60 keys / combinations guaranteed not to clash with anything else on your keyboard or interfere with 99% of software.

And X11 does support F13-F24. xev & vscode were misleading.
In my mind I thought F13 as a seperate key and results were SHIFT + F1 etc. even though what had produced was F13.

Additional Note: Discovered that in Neovim spontaneously (ditched VSCode for this reason).