Istrebitel's picture

How to force GameWindow to retain focus as long as it's present?

Greetings!

In my app, I periodically enter full screen mode, and I need it to stay that way until it Exit()s on its own. Normally, it works (when spawned, GameWindow goes on top and receives focus), however, some other app can steal the focus afterwards - for example, 7-zip finished unpacking and system wants to ask about file replacement, or some notification from some program happened to pop.

How to prevent those events from taking the focus away from my GameWindow, or, how do I bring focus back to it (like, if I detect it lost focus)?


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

You can detect focus loss using the FocusLost event.

It is not normally possible to prevent focus loss on Windows. Raymond Chen explains why in an excellent blog post: What if two programs did this?

As far as I know, the only way to prevent focus loss is to use kiosk mode. This is outside the scope of OpenTK.

Istrebitel's picture

An interesting point, however, it is invalid. There are no "rules" to be had about what PC or program can and cannot do, and that is because, they must do whatever the user needs. They are our unconditional servants, tools, not sentinent beings. Therefore, all control, and all responsibility, lies on the user. If my user needs for my program to always open .XYZ files, then it has to do so, and it is the user's fault, not progarm's fault, that he installed two different programs, both of which should always open .XYZ files. Same here - if a user wants to use my program, which has to stay focused no matter what, with some other program, which also has to do the same, it's the user's fault. And really, with this "safety from paradoxes and tricky situations", we can go as far as to prevent programs from flashing the screen (what if an epileptic person watches the screen right now?), deleting data on disk (what if someone else needs it?) and so on.

Anyways, I see this is indeed outside of OpenTK scope, I guess I will have to generally look for a way to make a program/window gain focus... probably some windows dll should have it...