How to Detect Lost Focus.

Blitz3D Forums/Blitz3D Beginners Area/How to Detect Lost Focus.

Moore(Posted 2008) [#1]
Ok Im creating a game in full screen 3d mode... I want the game to END if the user trys to switch to another app using alt+tab or what not. So how do I detect when the app is suspended or losses focus????


chi(Posted 2008) [#2]
you can either use

api_HasFocus() -> if in focus = true

or

api_IsIconic(hwnd) -> if minimized = true

(both commands come with user32.decls)


cheers, chi


Nate the Great(Posted 2008) [#3]
Why would you want the game to end if the user switched screens?


Gabriel(Posted 2008) [#4]
You do realize that lots of processes can cause your game to lose focus? I mean, things like virus checkers and instant messengers, those can momentarily steal the focus.


Moore(Posted 2008) [#5]
I'm developing a VERY strictly enforced RPG. I want to prevent the use of other apps such as messengers so players can't use them to "unnaturally" cooridate attacks or otherwise be distracted from the RP.