How does
autocmd FocusLost * call feedkeys("\<esc>")
(back to normal mode, if focus is lost)
translate to lua in init.lua?
I believe you should do:
vim.api.nvim_create_autocmd("FocusLost", { pattern = "*", command = [[call feedkeys("\<esc>")]] })
More information with: :help nvim_create_autocmd()