How do I change keyboard layout in (or before) i3 lockscreen?

If I sometimes lock screen through rofi_run logout script, I get locked there because I had the wrong keyboard layout and I’m unable to login. I’ve searched for a command to toggle or change the layout to an existing one in setxkbmap but I couldn’t find anything

Try

localectl set-keymap $map

Replace $map with the desired keymap.

Hello, thanks for the quick response.

That didn’t work, in case I’m using another layout and run this command to switch to US, I’m still typing with my old layout

I could run setxkbmap us before locking but then I’d lose my layouts everytime I unlock the screen

Try “loadkeys”

I’ve tried loading the default keymap using sudo loadkeys -d and tried loading the us.map from /usr/share/kbd/keymaps/i386/qwerty/us.map.gz but none of them worked, I still typed with my other layout in the terminal