Changing layer reverts keymap to default

Hi. So I have my keyboard attached to a USB switch and I have a script on each machine that fires when I switch the keyboard to that machine. The script uses switch-keymap.ts to change the keymap and this all works fine.

But as soon as I change the layer, say hitting the mod key, the keyboard reverts to the default layout.

However, I’ve discovered that if I use exec-macro-command.ts "switchKeymap {keymapId}" then this doesn’t happen and the keymap change persists correctly.

So while I now do have things working the way I want, I was wondering what the deal is with switch-keymap.ts ?

1 Like

Nice catch! Thanks for reporting it!

Fix is on its way: Fix Usb Switch Keymap getting reverted on first macro layer switch. by kareltucek · Pull Request #771 · UltimateHackingKeyboard/firmware · GitHub

To be precise the problem is that keymap gets switched back to previous keymap upon using a holdLayer ... macro. The reason is the mechanism that allows switching to layers of other keymaps (holdKeymapLayer ...) - after a regular keymap switch, the layer stack has to be resetted. Otherwise, the previous keymap remains in the base of the stack and will trigger a layer switch when the holdLayer command is released. This reset was missing in the usb command firmware code.

Oh wow! That is an incredibly quick response with both a fix and a detailed explanation of what was happening. That is fantastic. Thank you!

You are welcome :slight_smile: