2

The Numlock key sees little action in today's day and age, yet it's location in the (standard) keyboard layout is quite prominent.

Since I use a lot of spreadsheets, using the keypad for data entry is very convenient, with one caveat: the equal sign is quite hard to reach, when your right hand is on the keypad.

My idea was to re-map Numlock, such that it can act as both, Numlock and equals, with the former accessible through a modifier.

For this purpose I decided to make my own xkb keymap, as I tried the same thing with xmodmap but I had similarly bad results.

(file name is pb)

default partial alphanumeric_keys
xkb_symbols "basic" {
    
    name[Group1] = "PB (US intl with level 3 and level 5";
    key.type[Group1] = "EIGHT_LEVEL";

    include "us(altgr-intl)"

    //              (norm)     NLOCK     AltGr
    key.type[Group1] = "FOUR_LEVEL_MIXED_KEYPAD";
    key <NMLK> { [ KP_Equal, KP_Equal,  Num_Lock, Q ] };

    include "level3(ralt_switch)"
    include "level5(rctrl_switch)"
};

Now, as you can see, I added level 3 and level 5, when I want to expand my custom layout later, but I tested withou it, and it doesn't interfere with Numlock.

The behavior resulting from this is as follows when pressing the Numlock key:

(numlock is off)

  • Numlock: '='
  • Shift + Numlock: '='
  • AltGr + Numlock: (switches Num lock on)
  • AltGr + Shift + Numlock: 'Q' (I added this for testing)

This is alright, printing 'Q' when holding down AltGr and Shift was just to see if I can reach that shift level. However when Num lock is on, the behavior not satisfactory at all:

(numlock is on)

  • Numlock: (switches Num lock off)
  • Shift + Numlock: (switches Num lock off)
  • AltGr + Numlock: (switches Num lock off)
  • AltGr + Shift + Numlock: (switches Num lock off)

It seems to be impossible to make Num lock behave like a KP_Equal key, no matter what I try.

Originally, I wanted pressing Numlock to print an equal sign, and when holding Shift, to operate Num Lock on and off. Since that didn't seem to be possible, I opted for ISO level 3 (AltGr), but that doesn't seem to work either. What I want is that Numlock prints an equal sign no matter if Num lock is on or off, and switch Num Lock when holding down a mod key (which one, isn't really important to me, preferably Shift or AltGr).

18
  • I think (but I'm not sure) that since <NMLK> is affected by the state of the NumLock modified, but you don't want it to be, it means it's of the wrong type. Try to have this in the symbols section: key <NMLK> { type = "TWOLEVEL"; symbols[Group1] = [KP_Equal, Num_Lock]; }; Aug 4, 2020 at 19:40
  • Having that in the file, I'm getting an error: "Error loading new keyboard description".
    – polemon
    Aug 4, 2020 at 20:59
  • @Gilles'SO-stopbeingevil' OK, it seems the file wants , between the elements key <NMLK> {}, and the map is accepted, but I'm still getting the same behavior.
    – polemon
    Aug 4, 2020 at 21:08
  • Yes, my bad, I copied the parts separately and added the wrong punctuation. I'm sure what you want is possible because I have something similar with CapsLock, but I can't figure out how I'm doing that… What does the part of the output of xkbcomp :0 - corresponding to key <NMLK> look like? Does key <NMLK> { [ KP_Equal, KP_Equal, Num_Lock, Q, KP_Equal, KP_Equal, Num_Lock, Q ] }; instead of the 4-element list work any better? Aug 4, 2020 at 21:28
  • @Gilles'SO-stopbeingevil' OK, I did that, now this the behavior: when I have num lock on, and just push <kbd>Numlock</kbd>, it prints the equal sign, but also switches num lock off. I'm quite flabbergasted, this isn't what I was expecting at all.
    – polemon
    Aug 4, 2020 at 21:46

1 Answer 1

0

So. If you look at the ouput of `xev', take attention to the state,

  • If yo keep the keysym Num_Lock on this key, you will see a state of 10 even when pressing the key for the keysym KP_equal , without being locked. And because of it, when you are locked, pressing KP_Equal will unlock you.
  • Now you want to get rid of Num_Lock on this key so it will not generate this pesky state, while still locking on the appropriate layer, it is done like this :
replace key <NMLK> {
type[Group1]= "FOUR_LEVEL_MIXED_KEYPAD",
symbols[Group1]= [ KP_Equal, KP_Equal,  Num_Lock, Q ],
actions[Group1]= [ NoAction(), NoAction(), 
                   LockMods(modifiers=NumLock), NoAction()
};

Take care of the absence of underscore, otherwise it will not work.

  • Now you can verify the state; it should be ok in any case, but oviously this state doesn't mean anything anymore since you have deleted the Num_Lock keysym from your map. So you need to find a spare keycode you do not use, and assign him the Num_Lock keysym. In this example, I'll take the keycode 249
replace key <I249> { symbols[Group1]= [ Num_Lock ] };

Now it should correctly work :)

2
  • I tried your solution, but I still have the effect, that when Num Lock is on, and I press <kbd>Num Lock</kbd>, it prints an equal sign, but also switches off Num Lock. At this point I'm starting to believe it might be a problem with the keyboard controller, or something.
    – polemon
    Sep 6, 2020 at 15:30
  • my bad, I have updated the answer.
    – pillule
    Sep 9, 2020 at 23:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .