I did a more precise test.
When my mouse is where the window appears, the hasmouse returns true but if my mouse is for example in the corner of the screen when i launch the game, the hasmouse return false.
In fact i made a mistake while copying the code, the return Task.cont must not be in the “if hasmouse” statement or the task will never be launched again.