Question

I'm trying to remap the last row of my keyboard to mimic the Happy Hacking Keyboard layout. I created a .Xmodmap file with following the keycode changes. The below shows only the lines that have been changed manually in the Xmodmap file generated using xmodmap -pke > ~/.Xmodmap.

keycode 37 = Super_L NoSymbol Super_L
keycode 64 = Control_L NoSymbol Control_L
keycode 105 = Super_R NoSymbol Super_R
keycode 108 = Control_R NoSymbol Control_R
keycode 133 = Alt_L Meta_L Alt_L Meta_L
keycode 134 = Alt_R Meta_R Alt_R Meta_R

The above changes were loaded using

xmodmap ~/.Xmodmap

The changes were verified from running xev i.e. Alt key: Ctrl, Super key: Alt and Ctrl key: Super.

However, when I run emacs, it is still Alt key: Alt, Super key: Super & Ctrl key: Ctrl. And, the terminal can still be launched only by pressing Alt + Ctrl + t instead of Alt + Super + t. These applications still reflect the default keyboard layout, not in accordance to the new configuration in my $HOME/.Xmodmap file.

Added the xmodmap ~/.Xmodmap to the $HOME/.xinitrc file so that the changes are persistant across applications. This did not the work.

Also, added the following code to /etc/X11/xinit/xinitrc. But this did not work either.

if [ -f $HOME/.Xmodmap ]; then
    /usr/bin/xmodmap $HOME/.Xmodmap
fi

Kindly provide your suggestions.

Thank you for your time.

-Girish

A little backgroud:

Recently switched to Ubuntu from Windows. I use Emacs for writing code and have found it effective to map the keys as in HHK. It avoids hurting the pinky and RSI of the wrists.

Was it helpful?

Solution 2

Finally, got the keyboard to mimic the HHK layout (for the last row of the keyboard).

Had to add the command to clear the modifier keys before making the changes for the new keymap. Then, enabled the modifier keys.

clear control
clear mod1
clear mod4

keycode 37 = Super_L NoSymbol Super_L
keycode 64 = Control_L NoSymbol Control_L
keycode 105 = Super_R NoSymbol Super_R
keycode 108 = Control_R NoSymbol Control_R
keycode 133 = Alt_L Meta_L Alt_L Meta_L
keycode 134 = Alt_R Meta_R Alt_R Meta_R

add control = Control_L Control_R
add mod1 = Alt_L Alt_R
add mod4 = Super_L Super_R

Thank you @d4gg4d for sharing ur Xmodmap file. Else, I wouldn't have figured it out.

OTHER TIPS

For info, if you don't want to get into the pain of Xmodmap, you can also do a lot via gnome settings.

sudo apt-get install gnome-tweak-tool, open it, go to Typing, and check out the options for Ctrl key position and Alt/Win key behaviour:

enter image description here

You could probably also do this stuff via gsettings, but am not sure of the exact config entry name.

I was successful to swap my right hand ctrl and alt across the ubuntu system with following xmodmap,

https://github.com/d4gg4d/my-emacs/blob/master/.Xmodmap

But 13.10 ubuntu suffers bad kind of headache with key remapping. Therefore I think your problem is related to this issue as well:

https://askubuntu.com/questions/363075/xmodmap-doesnt-work-for-two-layouts/405553#405553

I'll suspect that automatically initing xmodmap during login will not work until this has been fixed in next ubuntu releases.

  1. Open the config /usr/share/X11/xkb/symbols/pc
  2. Modify the lines with Super_L and Control_L (exchange LWIN with LCTL and RWIN and with RCTL
key <LWIN> {    [ Super_L       ]   };
key <LCTL> {    [ Control_L     ]   };
key <RWIN> {    [ Super_R       ]   };
key <RCTL> {    [ Control_R     ]   };

3. Remove the cache rm -rf /var/lib/xkb/* 4. Restart X

Yes, Ubuntu is notorious for messing with your settings. If I understood correctly, you want to run xmodmap on startup.

What currently works for me is running it through Startup Applications (just type it in from dash). Press Add and fill in this command:

xmodmap .Xmodmap

If you want Alt as Ctrl (ie map ctrl to alt), Super as Alt and Ctrl as Super, and want that on both left and right hands, then on my ubuntu 16.10 you can simply do any of the following:

  1. Like hwjp's answer, use Gnome's tool to select the altwin:ctrl_alt_win option,
  2. In KDE similarly look into the System Settings/Input Devices/Keyboard/Advanced for the altwin:ctrl_alt_win option,
  3. On a terminal write setxkbmap -option altwin:ctrl_alt_win. Note that this is undone by setxkbmap -option.

This avoids using xmodmap and the KDE/Gnome settings will still be persistent.

Incidentally, I would have done the same but my Asus laptop does not have a right win key. So, in order to do the same on the left side and only swap alt with control on the right side, I have added an xkb option in /usr/share/X11/xkb/symbols/ that I can turn on/off again with something like setxkbmap -option tp500:emacs_b_row. If you want to know how, you can follow this answer on askubuntu. Mind that, in this last link you might not need his step 4 and you need sudo power. This method feels more appropriate and benign than the xkb solution by user259819.

I might have added this answer as a comment, but my reputation is low!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top