# How to Switch CAPS with both CTRL and ESC



## Lord_Devi (Mar 20, 2021)

Hello,

I'm relatively new to FreeBSD.  Long time Linux user.  I am trying to configure my keyboard inside of X to provide the following functionality to my Caps_Lock key:

- Holding Caps_Lock behaves as if holding down Control modifier.
- Tapping (Pressing) Caps_Lock sends ESC code.
- Tapping RIGHT_Control toggles Caps_Lock.

This is ultimately what I'm after, although I see a lot of other interesting options inside of setxkbmap(1) which could allow this functionality, and more perhaps. (LEFT_Control as Hyper sounds kinda neat!.)

The trouble I run into, is that using setxkbmap to set TWO options for caps lock doesn't seem to work.

From reading the manpage, an example of what might work are the following two commands:


```
setxkbmap -option 'caps:escape_shifted_capslock'
```

This makes Capslock do the ESC thing I'm looking for.  And still allows me to CapsLock easily. This isn't putting Capslock on the lower right hand CTRL where I am used to it being, but I could adapt easily to this new approach.

Then:


```
setxkbmap -option 'caps:ctrl_modifier'
```

This last option claims to be the last part of the puzzle for me.  It makes holding down Caps_Lock behave like a CTRL modifier key.

I've tested them both independently of each other, and they seem to do what I'm looking for.

BUT.. Not at the same time. 

I can't run both of those commands, and have their effects stack.

On linux in the past, I've done this by taking this fellows approach in this blog post:

https://www.dannyguo.com/blog/remap-caps-lock-to-escape-and-control/

He uses Xmodmap basically to just switch Caps and R_CTRL.  Then once that is setup, he uses a tool called *caps2esc *to add the Esc functionality on top.

I would LOVE to be able to just stack these setxkbmap options, is there any way I can do that?

There are so many fun looking options in that man page to try out. =/

Thanks for any help you can provide guys.  Cheers!


----------



## Lord_Devi (Mar 20, 2021)

Update: I have some limited success with this using the 'xscape'.

In my .xinitrc / .xsession I've done the following:


```
setxkbmap -option ctrl:nocaps &
xscape -e 'Control_L=Escape' &
enlightenment_start
```

While these two commands DO provide the sought after functionality, the .xinitrc auto start of xscape is NOT working.

The setxkbmap is taking from the .xinitrc, but for some reason 'xscape -e ...' is not taking.  I have to run that command AGAIN manually once I am actually on the desktop.

Still hoping for a solution to this somehow. =/


----------

