Search code examples
c#xamarinurhosharp

How to focus UrhoSharp window when app starts?


UrhoSharp example app from UrhoSharp template for Visual Studio should exit when ESC key is pressed:

Input.SubscribeToKeyDown(args => { if (args.Key == Key.Esc) Exit(); });

However, it seems that it does not.

I have found that I need to click the app window first and then press ESC. The problem seems to be caused that the app window doesn't have a focus when the app starts. (App's console window has focus when app starts.)

How to give focus to the app window in UrhoSharp?


Solution

  • Are you starting the program via the debugger with F5? If so, then use Ctrl+F5 instead to 'start without debugging' and the templates main window should have focus.

    I also usually set the mouse to visible as a default when starting on these projects via:

    Input.SetMouseVisible(true, false);