Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is it possible to swap the Left Shift and the Left CTRL keys using setxkbmap instead of xmodmap?

EDIT

I have switched to Fcitx, which works way much better with my keyboard layout and customized keymap than IBus in every respect. I highly recommend it.

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

xmodmap is obsolete; so indeed it should be done with the xkb tools.

The swap you want seems not to be included by default wth X11 files; so you have to write it yourself.

The page http://madduck.net/docs/extending-xkb/ helped me to understand and find a way to do it.

Create a file ~/.xkb/keymap/mykbd where you put the output of setxkbmap, it will be your base keyboard definition; eg:

setxkbmap -print > ~/.xkb/keymap/mykbd

then, create a symbols file to define your key swaping, put it for exemple in ~/.xkb/symbols/myswap

there, put the following lines:

partial modifier_keys
xkb_symbols "swap_l_shift_ctrl" {
    replace key <LCTL>  { [ Shift_L ] };
    replace key <LFSH> { [ Control_L ] };
};

then, edit the ~/.xkb/keymap/mykbd file, and change the xkb_symbols line to add "+myswap(swap_l_shift_ctrl)"

finally, you can load it with xkbcomp -I$HOME/.xkb ~/.xkb/keymap/mykbd $DISPLAY (you cannot use "~" for the -I parameter). It will probably sput a lot of warnings about undefined symbols for some rare keys, but you can ignore them (eg, redirect error to dave: 2> /dev/null).

if you want to be able to easily swap between a normal and your inversed ctrl/shift one; just create under ~/.xkb/keymap/ another file, without the extra "myswap" option, and load it with xkbcomp. You can make two small scripts to load them.

share|improve this answer
    
Thanks. It does work, but for once. The problem is that I am using an input engine called IBus. Whenever I switched the input method and then back by the key stroke "Ctrl + Space", Left Shift and Left Control are switched back. Any suggestion on how to avoid it. –  day Feb 21 '13 at 14:44
    
mmn, maybe IBus does itself some keyboard redefinitions. try xkbcomp $DISPLAY some.dump after and before calling IBus, and do a diff of the two dumps (those are complete keyboard definition); you will probably see differences. –  Pablo Saratxaga Feb 22 '13 at 10:09
    
Hmm, it does, how annoying. Any idea to get rid of the problem? Notice that the command setxkbmap -option caps:escape works. IBus remembered the swapped keys Esc and Caps_Lock keys But it does not do for the swapped Left Shift and Left Control keys. –  day Feb 22 '13 at 17:14
    
maybe IBus read the keyboard when launched. Try unloading IBus, changing your keyboard, and loading it again. If problem persists, then an IBus specific question should be made (and maybe report a bug; imho it is, IBus should detect keyboard changes and honour them) –  Pablo Saratxaga Feb 24 '13 at 7:11
    
Thanks, Pablo. I reported the bug. –  day Feb 28 '13 at 14:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.