19

How do I make the Caps Lock key work just like another Shift key?

There are loads of questions here about reassigning it, or having it launch a custom command. I just want it to work like another Shift key. I don't want any other keys to change what they do, just that one.

Keyboard Layout/Caps Lock key behavior won't do it, I don't understand how to remap it in CCSM.

I'm using a UK keyboard now but I learned to type on a US keyboard, the smaller left Shift key is DRIVING ME NUTS.

3
  • 1
    Possible duplicate of How can I remap the Caps Lock key to be Shift Lock? Jul 27, 2016 at 10:31
  • 1
    @David-yourfriend OP specifically said xmodmap doesn't work. Sep 2, 2016 at 11:24
  • 1
    In xkb this appears to have something to do with compatibility maps which translate certain key combinations into actions, rather than symbols. This will take more research and testing time than I have available at the moment. If I get the chance I'll dig into this further, if not perhaps this bread crumb will lead someone else in the right direction.
    – Elder Geek
    Sep 2, 2016 at 19:42

4 Answers 4

14
+250

Expanding on @Zacharee1 answer:

make a backup with cp /usr/share/X11/xkb/symbols/pc ~/pckeybak

then edit with gksu gedit /usr/share/X11/xkb/symbols/pc or your favorite editor.

Find the line (22) that says:

key <CAPS> { [ Caps_Lock ] };

and change it to

key <CAPS> { [ Shift_L ] };

and the line (36) that says:

modifier_map Lock { Caps_Lock };

and change it to

//modifier_map Lock { Caps_Lock }; (which should comment it out in effect disabling the locking)

Testing indicates that the Num Lock still works as expected. Further testing indicates that the keyboard indicator lights appear to be a bit dyslexic in 16.04 on even an unmodified system. Scroll Lock indicator on at login but Scroll lock off and Num Lock light off, but Num lock on. Tapping the left Ctrl key seems to resolve this behaviour and I'm not sure if it's related to my use of a KVM switch (which is possible)

Note: Further testing shows that the NumLock indicator light is flaky even without a KVM switch and has to be tapped twice to get back in sync with NumLock If you always leave it on you can ignore the light or if it bothers you you can tap it twice to get it back in sync. Why this occurs is likely a basis for a new question...

Another simple solution to your original problem would be to simply obtain an inexpensive US keyboard and use the US keyboard mapping.

Sources: @Zacharee1 answer and analysis of /usr/share/X11/xkb/symbols/pc and trial and error testing

5
  • So you had to disable that line 36 thing? Just changing to Shift_L was enough to completely disable capslock for me. Sep 3, 2016 at 18:30
  • @Zacharee1 I thought that it might be the cause of the impact on Numlock that Tom Brossman mentioned in a comment on your post and took it out for that reason only.
    – Elder Geek
    Sep 3, 2016 at 18:36
  • Hmm. That could be it. I'm seeing if I can get Zanna to test with a VM, since she has a UK board. Sep 3, 2016 at 18:38
  • @Zacharee1 That would be cool as I don't have that hardware available for testing and often rely on logic in cases where complete testing is not possible.
    – Elder Geek
    Sep 3, 2016 at 18:45
  • That did it finally, tested and working (for now at least). It is odd that the Num Lock light on my keyboard is out but the extra number keys are enabled by default when I log in and that's what I was after. Thanks! Sep 3, 2016 at 20:12
10

You can get there by adapting How to change CapsLock key to produce “a”? (for example).

Remove the Lock (= Caps Lock) modifier from the Caps Lock key, and declare that this key sends the Shift_L keysym.

remove Lock = Caps_Lock
keysym Caps_Lock = Shift_L

Alternatively, you could remove the Lock modifier and add the Shift modifier.

remove Lock = Caps_Lock
add Shift = Caps_Lock

Either way, these lines go into the file ~/.Xmodmap. Test by loading it with xmodmap ~/.Xmodmap; the file is read automatically when you log in under the default environment (or at least it was in the Gnome days).

3
  • 2
    Perfect, that worked. I made a new empty document in my home directory called '.Xmodmap', and pasted your first example into it. Then I typed 'xmodmap ~/.Xmodmap' in the terminal to make it take effect immediately. These are both explained in the linked answer. Thank you. Nov 26, 2011 at 21:44
  • The second set of commands don't work for me, but the first one works great. Pressing Caps Lock doesn't even turn on the keyboard light, so it doesn't even trigger my latent OCD. Jul 27, 2016 at 10:43
  • Good answer, Gilles ! Just to add to your answer, this can be done as one single command,too: xmodmap -e "clear Lock" -e "keysym Caps_Lock = Shift_L" and undone with setxkbmap -option , which doesn't write to ~/.Xmodmap file, but can be used when necessary , and added to Startup Applications. Very good answer ! Sep 3, 2016 at 18:20
7
+250

Ignoring my previous attempts at answering that failed, I found something that turns capslock completely into left shift. No toggling, I think it's persistent, and it's pretty simple.

First, I'd recommend making a backup, before I introduce how to change it.

Run sudo cp /usr/share/X11/xkb/symbols/pc ~/pckeybak

Now that there's a backup, let's get to the editing.

Use your favorite text editor to edit this file as root:

/usr/share/X11/xkb/symbols/pc

Find the segment that looks like this (it's near the top, line 22 for me):

key  <TAB> {    [ Tab,  ISO_Left_Tab    ]   };
key <RTRN> {    [ Return                ]   };

key <CAPS> {    [ Caps_lock             ]   };
key <NMLK> {    [ Num_Lock              ]   };

edit

key <CAPS>  {   [ Caps_lock             ]   };

to be

key <CAPS> {    [ Shift_L, Caps_Lock    ]   };

instead. (The Caps_Lock after Shift_L, may be unnecessary.)

Restart your display manager (usually sudo service lightdm restart) and capslock will now be left shift. (Note: My test machine uses GNOME, so I had to restart gdm. However, that caused some weird flickering in the fallback TTY, and gdm never restarted. I had to completely reboot.)

This one I was actually able to test, and can confirm it works.

Adapted from Permanent xmodmap in Ubuntu 13.04

8
  • Thanks, but this interferes with Num Lock which I leave on permanently. In my early troubleshooting, changing Caps_lock > Shift_L in /usr/share/X11/xkb/symbols/capslock also interfered with Num Lock. There is something different about 16.04, for example the Num Lock light used to remain on at boot but now it goes out at the LightDM login. When I test your solution it does change Caps Lock to Shift, but the first time I press Caps Lock the Num Lock toggles off, and I have to press Num Lock TWICE to get it back on (only the first time). Bizarre. Really appreciate the help so far though. Sep 2, 2016 at 7:00
  • Perhaps I need to ask a new question "How to prevent Caps Lock remap interference with Num Lock on 16.04?" but I'd love to find the root cause here. Either that or it's time to open the keyboard up and make some physical modifications to it... Sep 2, 2016 at 7:04
  • That's weird. Does numlock work again if you run xkbset nullify lock? Sep 2, 2016 at 10:05
  • @TomBrossman I don't know if this changes anything for you, but it does work for me. Instead of just Shift_L, put in Shift_L, Caps_Lock. Make sure the brackets line up. Sep 2, 2016 at 10:28
  • 1
    @TomBrossman I like to use sudo if it isn't dangerous, just to be sure :p. When I edited the file, the L for shift was capital and so was the the caps lock one. Weird. The NumLock thing is also weird, since it works fine for me. This whole thing is weird :p Sep 2, 2016 at 18:08
3

For 14.04

A one-liner:

xmodmap -e 'keycode 66=Shift_L'

BUT, in the unexpected case 66 is not the correct keycode, first run xev in console and press CapsLock. Then you will see something like:

KeyPress event, serial 27, synthetic NO, window 0x1200001,
    root 0x101, subw 0x0, time 6417361, (340,373), root:(342,393),
    state 0x0, keycode XX (keysym 0x0207, Caps_Lock), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

The correct keycode is the one indicated in the XX.

4
  • 1
    Look at the bounty message: Xmodmap trick no longer works and xkb handles this now.. Aug 31, 2016 at 22:43
  • Oh my! is it because of 16.04? It works on my 14.04. Bounty comment seem not to specify.
    – user308164
    Aug 31, 2016 at 22:50
  • I didn't make the bounty so I don't really know. Aug 31, 2016 at 22:55
  • Sorry, this is for a fresh 16.04 install. Left or right shift key would be fine, I picked left for the question because it is adjacent and xev sees them as different keys. Sep 1, 2016 at 21:44

You must log in to answer this question.

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