Works when debugging, but when run it doesn't

I’m trying to port this code to rust (and I have it done, to the point that it behaves exactly like the c app)

The problem with the c app (and thus with my app in rust) is that it works perfectly, when we debugging it, that is the onboard keyboard is spawned, embedded and the input is sent to the entry box. Unfortunately, this isn’t the case when we simply run this app. Then the situation is that it almost works. Keyboard is there but the entry doesn’t receive the input. Could somebody explain why?
Thank you

[Update]
I actually had a very small progress in investigating the issue and it appears that the “focus” is the problem.
If I start that application, switch to other and switch back to my app it works. But if I just run it and even I click on the window to “grab the focus” it is simply not working.