2

I wanted to remap Ctrl-N/Ctrl-P to Up and Down keys. And I found this post and did something like this:

! add Mode_switch
keycode 66 = NoSymbol NoSymbol
keycode 66 = Mode_switch

keycode 57 = n N Down
keycode 33 = p P Up

And it kinda works. But there's one problem - I actually wanted Caps Lock to be Ctrl and also do that. I can't seem to find a way.

1 Answer 1

0

Your remappings of Ctrl+N and Ctrl+P in your last two lines are fine. The problem lies in the attempt to remap the Caps_Lock button (keycode 66 decimal, or 0x42 hex).

Caps Lock is one of the modifier keys, along with Shift and Control (Ctrl). X.org maintains a table of modifier mappings as well as the familiar key mappings. xmodmap -pm will show you your current modifier map. You'll need to update that map as well as the keymap, as I explain below:

The (Caps) Lock modifier, that gives the characteristic behaviour of locking capitals on, won't release the physical key for other purposes unless you explicitly tell it to. Personally, I always used to pry off my Caps Lock key with a screwdriver, it annoyed me so much, so I'm happy to clear it entirely, with clear Lock.

(I've also seen people enable changes to their Lock bindings by surrounding them with remove MODIFIERNAME = KEYSYMNAME ... and add MODIFIER = KEYSYMNAME. Check out man xmodmap for details.)

clear Lock
keycode 66 = Control_L
add Control = Control_L

After the Lock modifier has been told to release the Caps_Lock key, you're free to remap that key (keycode 66 in line 2 of the snippet) to one of the Ctrl keys - in this case I've chosen the left one, hence the _L, but it doesn't really matter which. Now the Caps_Lock key "thinks" it's a Ctrl key, but the modifiers table doesn't yet know that we want to use it as a modifier.

The last line in my listing declares that Control_L is a new Control modifier, and should therefore act like a Ctrl key. Look at the before/after comparison of the modifier maps (from xmodmap -pm) below:

Before: the Caps_Lock key belongs to the Lock modifier. Before: the Caps_Lock key belongs to the Lock modifier.

After: the keycode identifying the physical Caps_Lock key (66/0x42) now identifies as an additional left Control key, still with Caps_Lock's original keycode, and has now moved from the Lock modifier to the Control modifier in the modifier map. The original left Control key is still there, too. After: the keycode identifying the physical Caps_Lock key (66/0x42) now identifies as an additional left Control key, still with Caps_Lock's original keycode, and has now moved from the Lock modifier to the Control modifier in the modifier map. The original left Control key is still there, too.

You must log in to answer this question.

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