0

I would like my Menu key (keycode 135) to act both as the regular context menu key when pressed alone, and also to have it emulate my XF86Audio* multimedia keys when used as a modifier, e.g. Menu+PgUp would emulate XF86AudioRaiseVolume.

I would be fine with setting the key combinations in KDE's Global Shortcuts instead of having them apply to all of X, but I'm not sure how to achieve either.

0

Components needed: xmodmap, xcape, xbindkeys.

xmodmap -e "keycode 135 = Hyper_R"
xmodmap -e "add mod3 = Hyper_R"
xmodmap -e "keycode any = Menu" # this is needed for xcape
xcape -e "Hyper_R=Menu" # for single key press on menu key

~/.xbindkeysrc:

# map Menu+Pause as Mute
"xdotool keyup Hyper_R keyup Pause key --clearmodifiers XF86AudioMute keydown Hyper_R key Control"
    Mod3 + Pause

# map Menu+PgUp as Volume+

"xdotool keyup Hyper_R keyup Prior key --clearmodifiers XF86AudioMute keydown Hyper_R key Control"
    Mod3 + Prior

# etc. 

The reason for such complicated xdotool call is:

  1. keyup Hyper_R keyup Pause - keys needs to be cleared, otherwise XF86AudioMute is sent while they're pressed and is not recognized as lone keypress
  2. keydown Hyper_R - so that the combination key (Pause in this case) can be pressed several times, useful for XF86AudioRaiseVolume for example
  3. key Control - so that xcape doesn't detect fake keydown Hyper_R and subsequent real key release, to avoid triggering Menu function

xdotools calls can be externed to some bash script, like:

#!/bin/bash

case "$1" in
"up")
    KEY="XF86AudioRaiseVolume"
    SHORT="Prior"
    ;;
"down")
    KEY="XF86AudioLowerVolume"
    SHORT="Next"
    ;;
"mute")
    KEY="XF86AudioMute"
    SHORT="Pause"
    ;;    
"next")
    KEY="XF86AudioNext"
    SHORT="End"
    ;;
"prev")
    KEY="XF86AudioPrev"
    SHORT="Delete"
    ;; 
"playpause")
    KEY="XF86AudioPlay"
    SHORT="Insert"
    ;;        
"stop")
    KEY="XF86AudioStop"
    SHORT="Home"
    ;;            
esac

xdotool keyup Hyper_R keyup $SHORT key $KEY keydown Hyper_R key Control

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.