You are not logged in.

#1 2009-06-13 05:25:08

chetan51
Member
Registered: 2009-04-23
Posts: 14

Remapping Alt and Super Keys

Hi guys,

I've been trying to remap my Alt keys onto my Super (Windows) keys and the Super keys on the Alt keys because my external keyboard has them switched. I tried all sorts of combinations of commands using xmodmap, but I havent been able to get it done. Can someone please help me with the bash commands needed to switch these key maps?

I tried:

> xmodmap -e "keycode 64 = Super_L"
> xmodmap -e "keycode 133 = Alt_L"

and that changed the Super key to an Alt key, but it didn't change the Alt key at all.

Thanks,
Chetan

Offline

#2 2009-06-13 09:25:02

Gen2ly
Member
From: Sevierville, TN
Registered: 2009-03-06
Posts: 1,529
Website

Re: Remapping Alt and Super Keys

The X server has a list of known keyboard mappings in /usr/share/X11/xkb/rules/xorg.lst. This is probably the best way to do it.  On my super keyboard roll I'm able to re link the control-key to the alt-win key:

    Option      "XkbOptions"    "altwin:ctrl_win"

Super L, should be likewise.

Last edited by Gen2ly (2009-06-13 09:26:19)


Setting Up a Scripting Environment | Proud donor to wikipedia - link

Offline

#3 2009-06-13 16:32:55

chetan51
Member
Registered: 2009-04-23
Posts: 14

Re: Remapping Alt and Super Keys

Thanks for that tip! But what if I want to change the mappings on the fly without restarting X? (I sometimes use the internal keyboard when the external one is misbehaving.) Xmodmap changes mappings without having to restart X. How can I use it to do that?

-Chetan

Offline

#4 2009-06-13 18:46:14

pauldonnelly
Member
Registered: 2006-06-19
Posts: 776

Re: Remapping Alt and Super Keys

chetan51 wrote:

Thanks for that tip! But what if I want to change the mappings on the fly without restarting X? (I sometimes use the internal keyboard when the external one is misbehaving.) Xmodmap changes mappings without having to restart X. How can I use it to do that?

I think your problem has two parts. The first part is that you're not doing the remove/add dance for your modifiers — you're just swapping the keysyms around. First you need to remove the modifier, then you need you change the keysym, then you need to put the modifier back on the new key. The second is that you may run into problems if you don't make the whole switch at once. Running sequential commands could potentially get strange. Here's what I'm using, to get you started. You'll need to figure out the proper modifiers, of course. Running xmodmap with no arguments will show you which modifiers are currently on which keys.

! Swap Caps Lock and Menu
remove Lock = Caps_Lock
! Caps lock is Backspace
keycode 66 =  BackSpace
! Menu is caps lock
keycode 135 =  Caps_Lock
add Lock = Caps_Lock

! Backspace is Multi_key
keycode 22 = Multi_key

! Right Alt is Right Control
remove Mod1 = Alt_R
keycode 108 = Control_R
add Control = Control_R

Offline

#5 2009-06-14 05:55:29

beroal
Member
From: Ukraine
Registered: 2009-06-07
Posts: 325
Website

Re: Remapping Alt and Super Keys

Hi, Chetan. If you are using HAL and you need to tune a specific keyboard, you can use HAL policies. Then you should not run commands on the fly.

Create a file below. Substitute ${...} with corresponding strings. I've used 'XkbOptions' value from Gen2ly's post.

> cat /etc/hal/fdi/policy/11-x11-input.fdi

<?xml version="1.0" encoding="ISO-8859-1"?>
<deviceinfo version="0.2">
<device>
<match key="info.capabilities" contains="input.keys">
<match key="info.udi" contains="${copy a value of this key from lshal's output}">
<merge key="input.x11_options.XkbModel" type="string">evdev</merge>
<merge key="input.x11_options.XkbLayout" type="string">us</merge>
<merge key="input.x11_options.XkbOptions" type="string">altwin:ctrl_win</merge>
</match>
</match>
</device>
</deviceinfo>

Disable keyboard plugin in gconf-editor, /apps/gnome_settings_daemon/plugins/keyboard. Restart HAL and X server.


we are not condemned to write ugly code

Offline

Board footer

Powered by FluxBB