alols / xcape

Linux utility to configure modifier keys to act as other keys when pressed and released on their own.
GNU General Public License v3.0
2.1k stars 117 forks source link

Caps_Lock=Escape generates both Caps Lock and Escape #112

Open Osse opened 5 years ago

Osse commented 5 years ago

I am tryin to map Caps Lock to Escape using xcape -e Caps_Lock=Escape. It generates an Escape event (I go to normal mode in Vim etc.) but Caps lock is still switched on afterwards. I have included some xev output at the end of the issue.

This is an Arch Linux but it is running inside VirtualBox. Not sure if that is supposed to affect things.

KeyPress event, serial 28, synthetic NO, window 0x1e00001,
    root 0x3ad, subw 0x0, time 1158598, (224,181), root:(1668,741),
    state 0x0, keycode 66 (keysym 0xffe5, Caps_Lock), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyRelease event, serial 28, synthetic NO, window 0x1e00001,
    root 0x3ad, subw 0x0, time 1158692, (224,181), root:(1668,741),
    state 0x2, keycode 66 (keysym 0xffe5, Caps_Lock), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

MappingNotify event, serial 28, synthetic NO, window 0x0,
    request MappingKeyboard, first_keycode 8, count 248

KeyPress event, serial 28, synthetic NO, window 0x1e00001,
    root 0x3ad, subw 0x0, time 1158692, (224,181), root:(1668,741),
    state 0x2, keycode 9 (keysym 0xff1b, Escape), same_screen YES,
    XLookupString gives 1 bytes: (1b) "
mbLookupString gives 1 bytes: (1b) "
FilterEvent returns: False

KeyRelease event, serial 28, synthetic NO, window 0x1e00001,
    root 0x3ad, subw 0x0, time 1158692, (224,181), root:(1668,741),
    state 0x2, keycode 9 (keysym 0xff1b, Escape), same_screen YES,
    XLookupString gives 1 bytes: (1b) "
FilterEvent returns: False
Osse commented 5 years ago

I get the equivalent behavior using the default map expression, namely that Control_L is pressed and released first, then Escape.

Liblor commented 5 years ago

Edit: I just realized that I had several instances of xcape running... Naturally it didn't work as expected.

~I have the same problem on Fedora 30:~

xcape debug output:

Intercepted key event 2, key code 66
Intercepted key event 3, key code 66
Intercepted key event 2, key code 9
Intercepted key event 3, key code 9
Intercepted key event 2, key code 9
Intercepted key event 3, key code 9
neoromantique commented 4 months ago

Same behaviour on x11/i3

~ 
❯ pgrep xcape
364775

~ 
❯ killall xcape

~ 
❯ xcape -d -e 'Caps_Lock=Escape'
Assigned mapping from "Caps_Lock" ( keysym 0xffe5, key code 66)
to "Escape" (keysym 0xff1b, key code 9)
sig_handler running...
Intercepted key event 3, key code 36
Intercepted key event 2, key code 66
Key pressed!
Intercepted key event 3, key code 66
Key released!
Generating Escape!
Ignoring generated event.
Ignoring generated event.
^[Intercepted key event 2, key code 66
Key pressed!
Intercepted key event 3, key code 66
Key released!
Generating Escape!
Ignoring generated event.
Ignoring generated event.
^[Intercepted key event 2, key code 37

Yet caps is being triggered

EDIT: This works as a workaround:

setxkbmap -option 'caps:ctrl_modifier' && xcape -e 'Caps_Lock=Escape' &

(from: https://askubuntu.com/a/750535)