tolga9009 / sidewinderd

Linux support for Microsoft SideWinder X4 / X6 and Logitech G103 / G105 / G710+.
http://cevel.net
Other
151 stars 26 forks source link

Remapping keys in X11 #52

Closed The-Plottwist closed 1 year ago

The-Plottwist commented 2 years ago

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:

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.

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

Cheers.

The-Plottwist commented 2 years ago

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]
The-Plottwist commented 2 years ago

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

Here are the steps that I have followed:

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...

The-Plottwist commented 1 year ago

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).