Article 5CDKY Remapping my keyboard with xkb: How do I make a key respect numlock

Remapping my keyboard with xkb: How do I make a key respect numlock

by
d745fba1cb70ab9dc02a80ee
from LinuxQuestions.org on (#5CDKY)
My laptop doesn't have dedicated Home/End/Page Up/Page Down keys in the traditional sense, but it does have a number pad. However, the keys are too spread apart on the number pad to quickly reach while typing, so I'm trying to consolidate them along the left edge. However, I also want to have the numpad continue to function for entering numbers when num lock is on. Here is a visual comparison of what I have now vs what I want. Since Sway apparently uses xkb files despite being Wayland, that's what I'm going with. I've tried adding the following lines to both /usr/share/X11/xkb/symbols/us and /usr/share/X11/xkb/symbols/keypad:

Code: key <KPSU> { [Prior, KP_Subtract ] };
key <KP7> { [Home, KP_7 ] };
key <KP4> { [End, KP_4 ] };
key <KP1> { [Next, KP_1 ] };
key <KP5> { [KP_Left, KP_5 ] };
key <KP9> { [KP_9, KP_9 ] };
key <KP3> { [KP_3, KP_3 ] };(I am fully aware that there is also KP_Prior, KP_Home, KP_End, and KP_Next which are meant to come from the keypad keys. However, some applications only respond to the "normal" ones and not the numpad ones, so I'm making them send the normal keys.) Regardless of where I added them, these modifications worked correctly for the 7, 9, 4, 5, 1, and 3 keys (provided that I also enable numpad:microsoft). For example, numpad 7 sends KP_7 when pressed with numlock on, sends Home when pressed with numlock off, and selects to the beginning of the line when Shift+Home is pressed. I want the minus key to behave similarly, sending KP_Subtract when pressed with numlock on, sending Prior/page up when pressed with numlock off, and highlighting up a page when pressed with shift. The modifications I made to the config would suggest that it would behave like this, but it's treated differently: Regardless of the num lock state, pressing just numpad minus always produces page up, and pressing Shift + numpad minus always produces KP_Subtract (which normally types a minus sign.)

The problem is that I can't seem to get that key to work. The closest I could get is the Arch Wiki section on xkb_types. That seems to tell me how the modifier behaviors are defined. I was able to find in /usr/share/X11/xkb/types/numpad which implied that keys could be assigned types, which would describe how they behave with the modifiers. It looks like numpad keys are supposed to have a type of KEYPAD, which seems reasonable. However, explicitly setting the type to KEYPAD using key.type[Group1]="KEYPAD" ; does not provide the intended behavior. All other keys behave correctly, but the minus key now always produces page up if pressed alone and highlights one page above if pressed with shift, regardless of numlock state, leaving no way for it to type a minus sign.

I'm out of ideas. Anything else I could try?latest?d=yIl2AUoC8zA latest?i=9-uzSHg35Bg:8uAtXDpfB_A:F7zBnMy latest?i=9-uzSHg35Bg:8uAtXDpfB_A:V_sGLiP latest?d=qj6IDK7rITs latest?i=9-uzSHg35Bg:8uAtXDpfB_A:gIN9vFw9-uzSHg35Bg
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments