# Ubuntu – How to set a certain keycode to a key and bind it to the right action

key-bindingkeyboardshortcut-keysxevxmodmap

I have a laptop with Swedish keyboard layout, everything works well with the keyboard. Due to injuries I am using an external ergonomic USB keyboard, this is where I am experiencing difficulties.

The external keyboard doesn't have a key for Control_R or ALT-GR (I guess that's ALT_R) which causes trouble because typing @, \$, € and {} or [] all uses ALT-GR in Swedish keyboard layout.

UPDATE:: This is not true. The keyboard comes with both Control keys but was messed up due to custom remapping, read how to manage that here. After a complete reset I it turns out that the external keyboard has Alt-GR (shown as ISO_Level3_Shift by xev) as well (though backticks was hard to find). ::END UPDATE

The keyboard has a built-in remapping feature as well as macro features but there's no way to remap keys from the on-board keyboard to the external keyboard (as far as I know)

I would like to set one of my keys on the external keyboard to have a new keycode (such as Control_R or ALT_R and then remap that to acting as ALT-GR – is this possible? The reason I don't want the keycode Control_L is, if I remap it then the other Control key will be remapped as well.

With xev I have checked what keycode is trigged by clicking the key of ALT-GR on my on-board keyboard and that's keycode 108 (keysym 0xfe03, ISO_Level3_Shift). After some reasearch I've noticed this is not expected for the ALT-GR key, but this key works as I expect.

With xev I also check the output for the key on the external keyboard which I desire to use as ALT-GR: keycode 105 (keysym 0xffe3, Control_L).

I have another key on the external keyboard outputting the exact same thing, that key is the one I use for Control_L, making the one I wish was ALT_GR redundant.

I have messed around with xmodmap to see if I can get what I need but alas, with no success. Here are a few scenarios.

xmodmap -e "keycode 105 = Alt_R" #=> This disables both Control keys and doesn't work like ALT-GR, virtually the key doesn't do anything.

xmodmap -e "keycode 105 = ISO_Level3_Shift" #=> Same as above

Is there a way to address these problems?

Setup:

showkey -s

This will print out the scancodes of the keys, so just press those left and right CTRL keys and see whether they have the same scancodes. After you verified that, wait 10 seconds and don't press any key, so the showkey program can return. Then switch back to X (ALT+F7).