Could try this, it worked for me.
In the project settings, uncheck “Should Flush Pressed Keys on Viewport Focus Lost”