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

xcape generates multiple escape keystrokes #123

Closed IngoMeyer441 closed 3 years ago

IngoMeyer441 commented 4 years ago

Hey, thanks for xcape. It makes life in Vim a lot more comfortable. :slightly_smiling_face: I use xcape for generating escape when capslock is released and setxkbmap for maping capslock to ctrl when pressed with another key:

# Use capslock as ctrl
setxkbmap -option 'caps:ctrl_modifier'
# But capslock alone acts as escape
xcape -e 'Caps_Lock=Escape'

That works. However, I recognized that xcape generates multiple escape keystrokes when capslock is released. You can test this with the following small Python script:

#!/usr/bin/env python3

import os
import sys
import termios

fd = sys.stdin.fileno()

def setup_terminal():
    old_term_settings = termios.tcgetattr(fd)
    new_term_settings = termios.tcgetattr(fd)
    new_term_settings[3] = new_term_settings[3] & ~termios.ICANON & ~termios.ECHO  # unbuffered and no echo
    termios.tcsetattr(fd, termios.TCSAFLUSH, new_term_settings)
    return old_term_settings

def reset_terminal(old_term_settings):
    termios.tcsetattr(fd, termios.TCSAFLUSH, old_term_settings)

def main():
    old_term_settings = setup_terminal()
    print(os.read(fd, 80))
    reset_terminal(old_term_settings)

if __name__ == "__main__":
    main()

Pressing escape prints b'\x1b'. Pressing capslock generates (for me) b'\x1b\x1b\x1b\x1b\x1b\x1b\x1b\x1b\x1b\x1b\x1b'. Any idea why this happens?

IngoMeyer441 commented 3 years ago

Ok, my fault. Xcape was executed by a script multiple times which was causing repeated escape key sequences.