Skip to content

Window input focus sometimes failing after showing&activating (Windows 11) #19324

Closed Answered by genejo
genejo asked this question in Q&A
Discussion options

You must be logged in to vote

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 for hwnd = win.TryGetPlatformHandle()

void ForceToForeground(HWND hwnd) {
    // Restore if minimized
    if (IsIconic(hwnd)) {
        ShowWindow(hwnd, SW_RESTORE);
    }
    
    INPU…

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@LaurentInSeattle
Comment options

@genejo
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by genejo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants