I'm on a 20.04 Ubuntu machine.

I've been trying to use a combination of setxkmap and xcape to map AltGr and escape onto my caps-lock key, where a quick key press acts as escape and a longer key press acts as AltGr.

I believed the desired behavior could be achieved by executing the following:

$ setxkbmap -option lv3:caps_switch
$ xcape -e 'Caps_Lock=Escape' -t 300

Once the setxkbmap command is executed however, the xcape process/daemon no longer makes caps-lock act as escape when tapped. I'm not entirely sure why since the xcape process is still running, so I might just simply be oblivious to how setxkbmap works (I tried executing the commands in a different order, with the same result).

How would I go about achieving the desired behavior?

Why does setxkbmap 'silence' the xcape daemon regardless of whether I execute xcape before/after executing the setxkbmap command?

2 Answers 2


setxkbmap has nothing to do with your issue, the documentation for xcape mentions (enphasis mine) :

-t <timeout ms>

If you hold a key longer than this timeout, xcape will not generate a key event. Default is 500 ms.

  • I am aware of the timeout option, however that does not really address my issue since the behavior I'm after inculdes the xcape timeout. I've tested even longer timeout periods (lets say I wasn't tapping quickly enough to generate the key event), but after executing setxkbmap -option lv3:caps_switch the caps lock key exclusively acts as AltGr, even with the xcape daemon running in the background. This is not an issue of xcape: if I reset setxkbmap by executing setxkbmap -option, the caps-lock key now seems to have desired effects of a timedout escape caused by xcape.
    – DBJ
    Apr 7, 2023 at 15:20

The desired behavior could be achieved by executing the following commands:

# create daemons that map Caps Lock with AltGr and Escape (escape is timed out) 
$ xcape -e "#66=Escape" -t 300
$ xcape -e "#66=ISO_Level3_Shift"
# changes current X keyboard session configuration
$ setxkbmap -option lv3:caps_switch

You must log in to answer this question.

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