Solved How to swap the left control key with the left shift key without using Xmodmap?

Good evening everybody,

I'm trying to swap the left control key with the left shift key. I can do this with Xmodmap but the problem is I have to retype Xmodmap .xmodmap each time X.Org is started.

I successfully modify the behavior of the caps lock key which acts now like escape. To do this, I've added to /usr/local/etc/hal/fdi/policy/x11-input.fdi the line
Code:
<merge key="input.x11_options.XkbOptions" type="string">caps:escape</merge>

Unfortunately, the option shift:ctrl does not exist in /usr/local/share/X11/xkb/rules/base.lst so I cannot use it the same way. My question is: is there a way to modify the file x11-input.fdi so the ctrl left key acts as shift and inversely? Any other proposition is welcomed.

Thank you for your time,

Pierre Stévens.
 
All you need to do is to put xmodmap ~/.Xmodmap into your .xinitrc. I use that to use the left Windows key as a "left AltGr" key and to disable Caps Lock (for Caps Lock I have to press both Caps Lock and left Shift). I've also heard of vim users having switched their Esc and Caps Lock keys.
 
I've put
Code:
xmodmap ~/.Xmodmap
in my .xinitrc but it partially works. Here is the content of .Xmodmap:
Code:
remove Shift = Shift_L
remove Control = Control_L
keysym Shift_L = Control_L
keysym Control_L = Shift_L
add Control = Control_L
add Shift = Shift_L

I don't know why but when X is started, both shift and ctrl act as shift. I need to xmodmap ~/.Xmodmap twice in order for it to work. Another thing, I'm using pekwm but I'm pretty sure it's without consequence. Here is the content of .xinitrc:
Code:
xmodmap ~/.Xmodmap
exec pekwm
 
There are two problems.

The first one is that you define Control_L and then in the next line "point it back" at itself.

The second one is that xmodmap doesn't work that way. xmodmap is about associating keycodes with a meaning. So, to swap the left Control key and the left Shift key you need two lines in which you associate Control_L and Shift_L and also any potential modifiers (such as Control_L and Alt).

A typical default association might look like this:
Code:
keycode 37 = Control_L NoSymbol Control_L
keycode 50 = Shift_L ISO_Next_Group Shift_L ISO_Next_Group
where the keycode is the code sent from the keyboard controller for any pressed key and the right hand side of the line is what X should take these keycodes to mean. So, "Shift_L" is a virtual key; it's what X is working with (e.g. in xkb processing) and X (in its higher levels) knows that whenever keycode 50 is received the user pressed what X is to understand as left Shift (based on the above definition).

For each key you can define the basic meaning (i.e. when the key is pressed without modifier), the meaning of the key with Shift modifier, etc. (Alt modifier, Ctrl + Alt modifier, ...). You can find out those keycodes with xev.

If you want to map any two keys you can simply swap their right hand side like so:
Code:
keycode 37 = Shift_L ISO_Next_Group Shift_L ISO_Next_Group
(... keycodes 38 to 49 ...)
keycode 50 = Control_L NoSymbol Control_L

HTH.
 
Sure, fonz. Here are the relevant parts:

This "disables" CapsLock for clumsy fingers. To activate CapsLock it must be pressed together with Shift.
Code:
keycode  66 = NoSymbol Caps_Lock Caps_Lock

And the next one makes the left Windows key work as a second AltGr key. I wanted that because when developing software on a non-English keyboard, some important symbols like {[]}@ braces work only with AltGr held. This feels quite unnatural as one needs to turb/bend ones right hand. As I obviously have no need for a Windows key I came up with the idea to use that as a "left AltGr". Now I can comfortably type those symbols :)
Code:
keycode 133 = ISO_Level3_Shift NoSymbol ISO_Level3_Shift

Warning: While I do assume that the Windows key has the same keycode on pretty much every keyboard you might want to verify it using xev. In case it's not 133, just put the right hand side of my entry to whatever happens to be your Windows key code.
 
Thanks for sharing. It will give me an idea of how to either disable useless keys or make them do something useful instead.
 
You are welcome.

Note that Caps Lock is a tricky beast. You can reassign it as I did but it will send a KeyRelease event, too, and unfortunately there is no way (that I know of) to change that, too. So the LED will turn on anyway and one must press Caps Lock again to reset the LED. The key itself, however, works fine.

And another hint. I completely disabled CapsLock (pressed alone, without Shift pressed, too). You can, however, as I did on another system also have "Shift_L" as the first item on the right hand side (rather than "NoSymbol") to have CapsLock (without a modifier) work simply as a Shift key alternative, i.e. a "one-shot" (rather than CapsLocks toggle mode).
 
This code also works fine. It's probably not the best strategy but it works. Here is the content of ~/.Xmodmap:
Code:
remove Control = Control_L
remove Shift = Shift_L
keysym Control_L = Shift_L
keysym Shift_L = Control_L
add Control = Control_L
add Shift = Shift_L
 
Back
Top