Home > Bash, Linux, Ubuntu > Remap one keyboard key in Ubuntu

Remap one keyboard key in Ubuntu

October 15th, 2019 Leave a comment Go to comments

If you want to remap one key to another you can use the command xev to find the keycodes. Then remap by using the command xmodmap.

Let’s say you want to remap the key F5 to F4. This might be useful if you have a Kensington laser pointer and want to use the laser beam without issuing a F5-keypress that interrupts your PowerPoint or Google presentation. We first find the keycode for F5, which is 71, and then remap it.

xev

KeyPress event, serial 34, synthetic NO, window 0x3c00001,
    root 0x191, subw 0x0, time 729495065, (926,341), root:(1055,472),
    state 0x0, keycode 71 (keysym 0xffc2, F5), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyRelease event, serial 37, synthetic NO, window 0x3c00001,
    root 0x191, subw 0x0, time 729495169, (926,341), root:(1055,472),
    state 0x0, keycode 71 (keysym 0xffc2, F5), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

The effect of the remap command is preserved until the next reboot.

xmodmap -e "keycode 71 = F4"

Keycode 56 is normally mapped to the “stop”-button on the Kensington remote to produce a ‘b’ for make the screen black during a presentation. This button can be reassigned to ‘k’ if you want to start a YouTube-video during a Google presentation.

xmodmap -e "keycode 56 = k"

When you want to restore the original keymappings, use code below.

xmodmap -e "keycode 71 = F5"
xmodmap -e "keycode 56 = b"

Ref: https://askubuntu.com/questions/296155/how-can-i-remap-keyboard-keys

Categories: Bash, Linux, Ubuntu Tags:
  1. No comments yet.
  1. No trackbacks yet.