-
Hi there, Context: showing & activating an Avalonia window with a global hotkey after previously hiding it or switching focus away from it. The window has a textbox which should start capturing input. Good part: when pressing the hotkey (handled via SharpHook) the Avalonia window is always brought to foreground. I'm using this code snippet:
Bad part: However in certain instances the input focus remains on whatever window/control was active at the time of pressing the hotkey. Scenario for the issue to occur:
The issue doesn't occur when:
I also tried using native calls like the ones below, but nothing seems to help with the scenario presented. Would anyone happen to know how to programmatically show & activate a window and have it capture input under any circumstance?
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Your app is willing to "steal" the focus, which is not always "desirable". So, showing is not doing it by default. Have you tried something like that? (in Ctor of main window)
=> Not tested with Avalonia, but was working in WPF years ago... |
Beta Was this translation helpful? Give feedback.
-
Thanks Lawrent. Sadly it didn't work, but it was worth a shot. Usually it's indeed not good UX, but in this case the application is meant to act like PowerToys search / Everything (voidtools) / Listary / Spotlight etc.. There you expect the focus to be grabbed and just start searching. |
Beta Was this translation helpful? Give feedback.
-
Oh wow, this is not an Avalonia issue - I was barking at the wrong tree. It's a known issue for Windows applications in general. I tried coding this feature directly using Win 32 API and encountered the same issue. Microsoft PowerToys Command Palette (former Run) solves it by hack-sending some mouse input before bringing the window to foreground. Pasting below some Win 32 API code that does this and works. After
|
Beta Was this translation helpful? Give feedback.
Oh wow, this is not an Avalonia issue - I was barking at the wrong tree. It's a known issue for Windows applications in general. I tried coding this feature directly using Win 32 API and encountered the same issue.
Microsoft PowerToys Command Palette (former Run) solves it by hack-sending some mouse input before bringing the window to foreground.
Pasting below some Win 32 API code that does this and works. After
DllImport
-ing all necessary functions and creating the needed structures for .NET things worked forhwnd = win.TryGetPlatformHandle()