6

I am using Debian Testing/Stretch with Xfce. I just bought this wired keyboard. I would like the num lock to be turned on by default, but I do not want to have the led indicator light on. This could be accomplished by disabling the num lock indicator altogether, reversing the state (showing the indicator light when the num lock is off), or all of the num-lock-off keys could be remapped to type numbers instead (with this I can type numbers when the indicator is on or off). setleds -L -num works but only in a tty session. Thanks

3 Answers 3

7

You can invert the meaning of Num Lock. With Xmodmap, put this in your .Xmodmap.

keycode  79 = KP_Home KP_7 KP_Home KP_7 KP_Home KP_7 KP_Home KP_7
keycode  80 = KP_Up KP_8 KP_Up KP_8 KP_Up KP_8 KP_Up KP_8
keycode  81 = KP_Prior KP_9 KP_Prior KP_9 KP_Prior KP_9 KP_Prior KP_9
keycode  83 = KP_Left KP_4 KP_Left KP_4 KP_Left KP_4 KP_Left KP_4
keycode  84 = KP_Begin KP_5 KP_Begin KP_5 KP_Begin KP_5 KP_Begin KP_5
keycode  85 = KP_Right KP_6 KP_Right KP_6 KP_Right KP_6 KP_Right KP_6
keycode  87 = KP_End KP_1 KP_End KP_1 KP_End KP_1 KP_End KP_1
keycode  88 = KP_Down KP_2 KP_Down KP_2 KP_Down KP_2 KP_Down KP_2
keycode  89 = KP_Next KP_3 KP_Next KP_3 KP_Next KP_3 KP_Next KP_3
keycode  90 = KP_Insert KP_0 KP_Insert KP_0 KP_Insert KP_0 KP_Insert KP_0
keycode  91 = KP_Delete KP_Decimal KP_Delete KP_Decimal KP_Delete KP_Decimal KP_Delete KP_Decimal

You may need to add xmodmap ~/.Xmodmap to your startup applications, I'm not sure if Xfce does this by default.

Doing it this way has the advantage that most of the time, you won't have NumLock on. A few programs have trouble with NumLock because they consider it to be a modifier and that causes their keyboard shortcuts not to work when it's on.

If you never turn off NumLock, you can disable the NumLock key while you're at it.

keycode 77 = NoSymbol

If you enjoy pain, you can use XKB instead. Here's my configuration which effectively makes NumLock always on. Create a file ~/.xkb/types/mytypes containing

// Digits without NumLock, cursor with NumLock. Shift swaps the meaning.
// Do it this way because I almost always want digits, but the NumLock state
// breaks key bindings in some applications.
partial xkb_types "invert_numlock" {
  type "KEYPAD" {
    modifiers = Shift+NumLock;
    map[None] = Level2;
    map[Shift] = Level1;
    map[NumLock] = Level1;
    map[Shift+NumLock] = Level2;
    level_name[Level1] = "Base";
    level_name[Level2] = "Number";
  };
  include "extra(keypad)"
};

Create a file ~/.xkb/symbols/mysymbols containing:

partial xkb_symbols "mykeypad" {
    key  <KP7> {         [            KP_7,         KP_Home ] };
    key  <KP8> {         [            KP_8,           KP_Up ] };
    key  <KP9> {         [            KP_9,        KP_Prior ] };
    key  <KP4> {         [            KP_4,         KP_Left ] };
    key  <KP5> {         [            KP_5,        KP_Begin ] };
    key  <KP6> {         [            KP_6,        KP_Right ] };
    key  <KP1> {         [            KP_1,          KP_End ] };
    key  <KP2> {         [            KP_2,         KP_Down ] };
    key  <KP3> {         [            KP_3,         KP_Next ] };
    key  <KP0> {         [            KP_0,       KP_Insert ] };
    key <KPDL> {         [      KP_Decimal,       KP_Delete ] };
};

Run the following shell command as part of your X initialization startup (add other options to the setxkbmap call as desired):

setxkbmap -types "complete+mytypes(invert_numlock)" \
          -symbols "us+compose(menu)+mysymbols(mykeypad)" \
          -print | xkbcomp -I ~/.xkb - "$DISPLAY"
4
  • I've created ~/.Xmodmap (correcting KPDelete on last line). I've set xmodmap ~/.Xmodmap to run at login. I've logged out and in again and even rebooted. When I run xmodmap ~/.Xmodmap in the terminal it does not return any error. The keys remap is not working for some reason. I wonder if there is a way I could remap using the /etc/default/keyboard file instead, perhaps the XKBOPTIONS. I use this file to swap my caps and escape keys for Vim. It is fine if it is a system-wide change. No one else uses my machine. Thanks
    – jbrock
    Jan 16, 2017 at 0:50
  • @jbrock Strange. This comes directly from my configuration (I have numlock effectively always on), and I don't see why it wouldn't work everywhere (assuming you have a PC keyboard and a Linux installation from the last decade or so). You can do the same thing with XKB, but it's harder, there's no option for that, you have to build your own settings. I have code to do it though, I'll edit my answer. Jan 16, 2017 at 10:30
  • I tried the second solution (the one involving pain), but the setxkbmap command threw an error. I give up on the software solution. So, I just popped the key off and put a little black paint I had over the transparent part inside the key. Minor annoyance gone. Thanks for the thorough answer. You have my upvote. :)
    – jbrock
    Jan 17, 2017 at 4:57
  • I also tried the first solution with a different keyboard, and it did not work with it either. It must be something strange with my system.
    – jbrock
    Jan 17, 2017 at 4:59
4

If “num lock turned on by default” means “keys on the numpad by default” and you don’t want/don’t care about navigation on the keypad:

setxkbmap -option numpad:mac <layout>

So for the us layout:

setxkbmap -option numpad:mac us

Now the numpad always enters digits, no matter the num lock state.

Reference: xkeyboard-config man-page

1
  • 1
    I had forgotten about my post here. This is great. This actually makes a sweet difference for me today even though I have a different keyboard. Thanks! :)
    – jbrock
    Mar 13, 2019 at 4:20
1

You might be able to turn off the led in X11 each time you give the command

xset -led named "Num Lock"

or try explicit numbers like xset -led 3.

You must log in to answer this question.

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