How to Map my enter key to a different key
You need to have two app: xev and xmodmap, both are commandline-tool.
Run xev. Then press the key whose behaviour you want to change. i.e. Enter. and then xev
will output some information about the pressed key. Pay attention to the third line. It should be like this:
state 0x10, keycode 110 (keysym 0xff55, Prior), same_screen YES,
In this example Prior is the name of the behaviour the key is assigned to at the moment, the number keycode is the internal id to recognize the key. Now do this with another key i.e. PgDown give this output
state 0x10, keycode 115 (keysym 0xff56, Next), same_screen YES,
Here again the interesting part for us is keycode 115 and Next. Now, when you want to swap the two keys use xmodmap.
xmodmap -e "keycode 110 = Next"
This changes the key with keycode 110 on your keyboard to the action Next. It's pretty simple.
How to press 'Enter' if the key does not work
If you are lucky to have a terminal open, press simultaneously Ctrl
+Shift
+U
, then press Shift
+A
(uppercase A) to insert the Unicode for 'Enter'.
Otherwise you will have to use an on-screen keyboard (there may be one installed as an Accessibility tool) or use an external keyboard.
Remap key in X11 desktop
-
Obtain the keycode of the key you want to remap by using the
xev
command.KeyRelease event, serial 34, synthetic NO, window 0x4a00001, root 0xc5, subw 0x0, time 482692681, (-95,23), root:(499,342), state 0x11, keycode 62 (keysym 0xffe2, Shift_R), same_screen YES, XLookupString gives 0 bytes: XFilterEvent returns: False
Example output when pressing the right shift-key, which has keycode 62.
-
Remap the desired keycode to
Return
using thexmodmap
command, e.g.:xmodmap -e "keycode 62 = Return"
Remaps keycode 62 from
Shift_R
toReturn
. -
When you are happy with your current keymap and want to use it in future X-sessions, run the following command to save it:
xmodmap -pke > ~/.Xmodmap
Remap key in native Linux console
- Kernel keycodes are different from X11 ones. I found this keycode table in a quick Google search. I would choose
R Shift
which has the kernel keycode 54. -
Run the following command to dump your current keymap:
dumpkeys > ~/keymap.dmp
-
Now, modify the dumped keymap: You need to copy the behaviour of keycode 28 to the new keycode, i.e. keycode 54 if you want to use right-shift. You can do this manually in a text editor or use the following commands (copies behaviour from keycode 28 to keycode 54):
sed -n '/keycode *28 = /p' ~/keymap.dmp > ~/keymap.return sed -i 's/28 =/54 =/' ~/keymap.return sed -e '/keycode *54 = /!b;r '$HOME'/keymap.return' -e 'd' ~/keymap.dmp > ~/keymap.new
Your new keymap is now in ~/keymap.new
-
Load your new keymap in the console (requires root access):
sudo loadkeys ~/keymap.new
Happy about the result? On Ubuntu you can change the default keyboard settings in
/etc/default/keyboard
. Copy your modified keymap file to a safe location and find out how to load it automatically at startup, so you don't need to runloadkeys
every time.