Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remapping keys in X11 #52

Closed
The-Plottwist opened this issue Jan 9, 2022 · 3 comments
Closed

Remapping keys in X11 #52

The-Plottwist opened this issue Jan 9, 2022 · 3 comments

Comments

@The-Plottwist
Copy link

The-Plottwist commented Jan 9, 2022

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 Logitech G103 #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.

@The-Plottwist
Copy link
Author

The-Plottwist commented Jun 21, 2022

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
Copy link
Author

The-Plottwist commented Jun 21, 2022

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

@The-Plottwist
Copy link
Author

The-Plottwist commented Jun 26, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant