Is it possible to force OF app window to maintain focus?

#1

I am making an OF app for Windows 10 and I have a problem with another app, working with the OF app, opening a window every so often and stealing focus from the fullscreen OF app.

Is there any way to prevent this either by disabling focus stealing or forcing the OF app to maintain focus?

#2

Call SetWindowPos with HWND_TOP
See https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowpos

1 Like
#3

Thanks for the response. Tried your suggestion as specified here by Zach, but it doesn’t seem to do the trick. It might only bring the window to the front, but not focus it.

#4

It is a brute force method, but what about writing the following in update?

void ofApp::update()
{
    HWND AppWindow = GetActiveWindow();
    SetFocus(AppWindow);
    SetForegroundWindow(AppWindow);
    SetActiveWindow(AppWindow);
}

How about this?

1 Like
#5

Hi,

A dirty fix I made some years ago was to use AHK.

KeepFocus.ahk

loop:
WinWaitActive, ahk_exe annoying_app.exe
WinActivate, ahk_exe of_app.exe
goto, loop

Once started, the script wait for a window for annoying_app.exe to receive the focus, then give the focus back to the of_app.exe window.