Barrier Karabiner and Vim. A tale of two devices and keymapping

This might be a bit niche, but here is the problem I am trying to solve. I have two computers. A PC and a mac laptop. I often program on my mac but with my PC’s keyboard. I use Barrier to do so. This lets me share my mouse and keyboard between my devices. It works great.

I also have remapped my caps lock to control and escape on hold and tap respectively. I used Karabiner-Elements to do so and it works when I am using my laptop’s keyboard.

This is where the problem begins. Whenever I use my PC’s keyboard to code and try to hit caps lock. It functions like a regular capslock instead of executing my keybinds. I have power toys on windows doing the same thing that Karabiner is doing on my mac and the issue still persists. I even tried making a hotkey in Barrier to do the same; it works but, in the process, it also turns on the capslock. I was wondering if anyone had any suggestions to fix this problem. It looks like Karabiner doesn’t recognize the Barrier keystrokes as it’s probably intercepting the keyboard input and failing to recognize whatever method Barrier is using to type. Does anyone have any suggestions? This really disrupts my workflow as I either am forced to code with my laptop on my desk or I have to work without vim.

Disclaimer: I have no experience using barrier.

My idea: map capslock to escape on both systems. Hopefully a simple esc is easier to get from Windows to Mac. Then, use a thirdparty software to map “hold escape” to control.

Second disclaimer: I actually never tried to map “hold escape” to control, but I use “hold esc” in combination with other keys to trigger functions on both OSs. So this might or might not work. It works for me controlling a PC via Remote Desktop from a Mac (though to be fair, I disabled most of the stuff on the PC, because I was never sure in which layer I was, and the layers were quite different. When I wrote the Windows layer, I was using the PC directly). I do use the simple escape regularly, though.

More detailed: You can remap capslock to escape in windows by editing the registry. In macOS, you can do the same via settings.

To map “hold escape” on Mac you can use Hammerspoon. Worst case you have to write a loop assigning esc+other key to ctrl+other key.

On windows I use Autohotkey for similar stuff, though I am not sure about “modifier mapping” or assigning mappings in loop for many letters in AHK. (Worst case you write a script to write out all those mappings.)
In both cases, I only had the need to map specific combinations with esc.

Hope this gives you at least a direction to look in.

I tried this in a sense. The issue I had is that barrier still sends across the caps lock signal alongside the esc. I already have my caps disabled on windows.

Hm, so barrier receives the keyboard input before the registry change takes effect?
That seems really weird, because as far as I know, registry changes are even active when not logged in, eg when entering the password. But of course this might be the case, I don’t much about the hooks where barrier could grab the input.

Or maybe barrier gets the capslock state from somewhere else.

In this case, I think you should ask some barrier people. I would open an issue on their GitHub.

Good luck!

Oh wait. I was using windows powertoys. I think registry might work.

1 Like

Right, that works.

To summerize for future people

I remapped caps to cntrl in key sharper on windows.
then used a hammerspoon script to fire out a escape if its a quick control.

I also kept my Karabiner script so that it works when I’m using my mac keyboard.

1 Like