9

On my Thinkpad laptop I can easily change the Back/Forward keys to something else (I usually map them to PageDown/PageUp), as they have their own keycode (166 and 167):

xmodmap -e 'keycode 166=Prior'
xmodmap -e 'keycode 167=Next'

However, on my Thinkpad USB keyboard, the Back/Forward keys seem to be hard-mapped to Alt+Left and Alt+Right, respectively, so I cannot use xmodmap to remap them. Is there any other way I can remap them? I've already tried xautomation, but that didn't work.

This is what 'xev' shows me when I press the Forward key:

KeyPress event, serial 36, synthetic NO, window 0x4e00001,
    root 0xb4, subw 0x0, time 65023191, (16,-20), root:(641,33),
    state 0x0, keycode 64 (keysym 0xffe9, Alt_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyPress event, serial 36, synthetic NO, window 0x4e00001,
    root 0xb4, subw 0x0, time 65023191, (16,-20), root:(641,33),
    state 0x8, keycode 114 (keysym 0xff53, Right), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyRelease event, serial 36, synthetic NO, window 0x4e00001,
    root 0xb4, subw 0x0, time 65023271, (16,-20), root:(641,33),
    state 0x8, keycode 64 (keysym 0xffe9, Alt_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyRelease event, serial 36, synthetic NO, window 0x4e00001,
    root 0xb4, subw 0x0, time 65023271, (16,-20), root:(641,33),
    state 0x0, keycode 114 (keysym 0xff53, Right), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False
2
  • 1
    If the keys have keycode, they can be remapped right? Is it any different than the caps lock key? This page remaps it well it seems. I haven't tried it. Just suggesting. efod.se/writings/linuxbook/html/caps-lock-to-ctrl.html
    – Bibhas
    Jan 18, 2012 at 21:11
  • The problem is exactly that it doesn't have a keycode and instead is hard-wired to alt-left/alt-right Apr 30, 2012 at 14:30

2 Answers 2

0
  1. Install xdotool
  2. Create a script or shell alias for the keypress command you want to run (xdotool key --clearmodifiers Page_Down)
  3. Bind that script/alias to the sent combo (Alt+Left) in your desktop environment's Hotkey/Shortcut config.

Note that in gnome-control-center it doesn't seem to be possible to assign the Back/Forward buttons of the USB keyboard to a shortcut (you can actually assign them, but the command/action you mapped to it will never be called/happen), so you might need to use something else, like compiz' Commands plugin.

2
  • 1
    Thanks for the suggestion @sleighboy. I'd tried that with xautomation, but it didn't work. See my own answer, below, as to why Apr 30, 2012 at 14:56
  • 1
    Actually, this should be the final answer and I'll just explain here why it didn't work. The command to run should be xdotool key --clearmodifiers Page_Up and for some reason assigning the Back/Forward button as the accelerator of a shortcut on gnome-control-center doesn't seem to work, but if you use compiz' 'Commands' plugin it will work. Apr 30, 2012 at 15:29
1

I put this in my .bashrc:

# this maps the previous and next page buttons to pgup and pgdown 
xmodmap -e "keycode 167 = Next" 
xmodmap -e "keycode 166 = Prior"

works great, but doesn't seem to cut it in virtualbox 6 for some reason.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .