Set Focus to Window

Short: how can I set the focus to the window and all TextFields loose their focus/cursor?

Long: I make a simple calculator app and I have several TextFields where the user can set some special values. When the user sets those numbers and want to enter numbers for calculation he can either press the buttons 1,2,3, or should be able to press the numbers on his keyboard. Detecting pressed key is easy with the event KeyDown/KeyUp in the window. But only if the focus is not set to the TextFields (otherwise he would enter the the number to the TextField and ‘calculator-number’). So how does a normal user react to this situation? He clicks somewhere in the window to leave the TextField. But Xojo doesn’t remove the focus of the TextField when I click into the windows. Cursor is still in the TextField.
Tried a windows.SetFocus on MouseDown event without success.

ClearFocus

You can also use labels instead of TextFields if the input is to be made through keyDown.

Perfect! Thank you.

Ahhh! -After several hours of testing and searching this finally solved the issue on my mac app.
-I had no luck with window.setfocus. Is that supposed to work?

-What do you do on windows? The docs says (on ClearFocus) “On Windows only, the application also no longer receives KeyDown events.”

[quote=149032:@Roger Jönsson]Ahhh! -After several hours of testing and searching this finally solved the issue on my mac app.
-I had no luck with window.setfocus. Is that supposed to work?

-What do you do on windows? The docs says (on ClearFocus) “On Windows only, the application also no longer receives KeyDown events.”[/quote]

If you still need to receive KeyDown in Windows, try setting the focus on the window, and if it does not work, you can use a TextField placed out of the window area (TextField.Left = -100 or something like that) to which you give focus so it catches keydown.