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

mapping backslash to a modifier loses bar character #120

Open sidequestboy opened 4 years ago

sidequestboy commented 4 years ago

I've mapped my backslash character to a spare modifier using the following:

xmodmap -e "keycode 51 = Hyper_L"
xmodmap -e "remove mod4 = Hyper_L"
xmodmap -e "add mod3 = Hyper_L"
xmodmap -e "keycode any = backslash"
xcape -e "Hyper_L=backslash"

but now when I want to type a vertical "bar" character, it inserts a backslash.

How can I preserve my shifted bar character?

supremesnickers commented 4 years ago

I had similar issues using xcape in combination with Xmodmap while trying to replicate Ethan Schoonover's modifier setup. Xmodmap:

clear mod4
keycode 23 = Hyper_L
keycode 51 = Hyper_R
keycode 133 = Super_L
keycode any = Tab
keycode any = backslash

When I now run xcape -e "Hyper_L=Tab;Hyper_R=backslash", pressing tab by itself gives both Hyper_L and tab, pressing the backslash key by itself also gives both Hyper_R and backslash. Pressing Shift together with those keys doesn't make any difference.

I analyzed the pressed keys with this command: xev | grep -A2 --line-buffered '^KeyRelease' | sed -n '/keycode /s/^.*keycode \([0-9]*\).* (.*, \(.*\)).*$/\1 \2/p'.

dadaurs commented 3 years ago

I also had the same issue

The easiest way I found to circumvent this was to use xmodmap to essentially reconfigure the backslash character. The way you do this is by simply running

xmodmap -e "keysym  backslash = backslash bar"

After you've run this, everything should be back to normal

jaavedd9 commented 2 years ago

After spending too much time, the following ~/.xession worked for me, @supremesnickers I was facing the same issue and it was causing my machine to hang when hitting backslash + tab it was getting into never ending loop. Some how this script works, I don't understand all of it though, figured out by hit and trial. My OS is Debian 11.

#!/bin/bash
# hyper keys configs that worked
# from https://github.com/Zetagon/dotfiles/blob/master/xsession
# xbindkeys --defaults > $HOME/.xbindkeysrc

# kill xcape process, without this everytime this script is run it is multiplying backslash and tab keys 
# multiple xcape process causing this issue
pkill xcape
xbindkeys
# Log stderror to a file 
#exec awesome 
#    # No error logging
#    #dwm >/dev/null 2>&1
setxkbmap -option "caps:ctrl_modifier"
setxkbmap -layout us,se -option grp:shifts_toggle

# Make tab a superkey when held down, tab when pressed alone
xmodmap -e "keysym Tab = Hyper_L"
xmodmap -e "remove mod4 = Hyper_L"
xmodmap -e "keycode any = Tab"
xcape -e "Hyper_L=Tab"

# Make backslash a superkey when held down, backslash when pressed alone
xmodmap -e "keysym backslash = Hyper_R"
xmodmap -e "remove mod4 = Hyper_R"
xmodmap -e "keycode any = backslash"
xcape -e "Hyper_R=backslash"

# to restore pipe when clicking blackslash with shift
# from here https://github.com/alols/xcape/issues/120
xmodmap -e "keysym  backslash = backslash bar"