6

I can only set separately: switching layouts on caps lock or swap escape and caps lock keys, but has no success in trying to do it simultaneously. The final variant I want is to get caps lock behavior like escape key and use escape key for layout switching.

I have tried something like this:

setxkbmap -option grp:switch,grp:caps_toggle,grp_led:caps,caps:swapescape us,ru
Mitch
  • 107,631

2 Answers2

4

You should be able to swap around the keys with xmodmap if you can't quite do it with setxkbmap. You need the remove Lock modifier for caps lock, as it is a 'special' key.

remove Lock = Caps_Lock
keycode 66 = Escape NoSymbol
keycode 9 = Caps_Lock ISO_Next_Group

You could place the above in your ~/.Xmodmap, which is still read at startup if the correct command is in your ~/.xinitrc, as I explain further in this answer:

However, you cannot easily mix the xmodmap and setxkbmap commands, as the latter cancels out changes made with the former, as we discussed in the comments.

To execute these xmodmap commands in the terminal to test them, you would run, for example,

xmodmap -e "remove Lock = Caps_Lock"

but you would only place remove Lock = Caps_Lock in your ~/.Xmodmap file, as I explain further in my above linked answer.

  • Thanks for your answer, but this still doesn't helps me. After doing this caps lock and escape buttons works in a similar way: both simultaneously switches caps lock mode and works like escape. – simplylizz Oct 29 '12 at 11:47
  • @simplylizz Ok- I'm still trying to find a solution for it. –  Oct 29 '12 at 11:48
  • Thanks. As for me I think that the root of problem is in mixing xmodmap and setxkbd commands. Looks like they abandones effects of each other. – simplylizz Oct 29 '12 at 11:51
  • @simplylizz Yes, I think that might be the problem. –  Oct 29 '12 at 11:53
  • Thanks for your answers, just found valid answer after looked here: http://askubuntu.com/questions/94503/how-to-swap-remap-the-caps-lock-key-with-tab-key – simplylizz Oct 29 '12 at 12:21
  • @simplylizz ok- I have tried my edited answer and it also seems to work. –  Oct 29 '12 at 12:29
  • Correct your answer to contain this lines in config: remove Lock = Caps_Lock; keycode 66 = Escape NoSymbol; keycode 9 = ISO_Next_Group Caps_Lock ISO_Next_Group. If you know how to make working caps mode in this case on shift+caps this would be perfect. In any case I'll accept your answer because you adviced right direction to me. :) – simplylizz Oct 29 '12 at 12:30
1

Use xmodmap to switch the keys.

You can write a file ... i.e. name it .switch_keys

keycode 9 = Caps_Lock
keycode 66 = Escape

This redefines the keycodes on my keyboard. Check with xev if your keyboard uses the same keycodes.

Save the file and install the modmap by running xmodmap .switch_keys. Do this after you configured the layout switching with setxkbmap.

After that your Escape key works as Caps Lock and vice versa.

Paul Hänsch
  • 3,197
  • BTW, I use xmodmap to get german umlauts with my us layout. I defined 'AltGr' as Mode_switch and i.e. keycode 38 = a A adiaeresis Adiaeresis for typing ä using AltGr + a. For writing cyrillic this could be a bit straining though. – Paul Hänsch Oct 27 '12 at 21:34
  • Thanks for the answer, but after doing this I've got strange behaviour: Caps Lock button makes 2 actions - switches Caps mode and works as Escape. Also Escape buttin works like Caps Lock (in meaning of switching registers) but not switches layouts. – simplylizz Oct 28 '12 at 15:26
  • Oh cool, after now trying it out myself i got the same... seems that caps lock is special somehow... grml – Paul Hänsch Oct 28 '12 at 15:28