Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I tell if a glut window has focus? Im using c#/tao, Ill use p/invokes if necessary.

Basically I want to ignore input if it doesn't have focus.

share|improve this question
I've not used glut before, but it seems odd that a window would be receiving input messages if it didn't have focus. Are you sure this is something you need to do manually? – Mike Strobel Aug 9 '10 at 20:40
Since these are not game development exclusive topics, this question belongs at Stack Overflow where you should get a much better response. – Ricket Aug 9 '10 at 20:41
Im using GetAsyncKeyState for input rather that glut. – Sam Aug 12 '10 at 14:53

Here's the solution I've got so far

static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
static extern IntPtr GetFocus();

public bool HasFocus(string windowName)
    IntPtr windowHwnd = FindWindow(null, windowName);
    if (windowHwnd == IntPtr.Zero)
        return false;
    return windowHwnd.ToInt32() == GetFocus().ToInt32()
share|improve this answer
If you are ok with windows specific code, this would work fine i guess – Toad Aug 14 '10 at 13:11

I'd guess you have to use the regular win32 func to get the active window handle and compare it to your own. GLUT's focus functions don't behave as expected in Windows as they're based on move over to focus.

Edit: Wait...I assumed Windows. Not sure that's a correct assumption.

share|improve this answer
On Windows, he may want to compare his window handle to both the active window and the foreground window, ensuring that both match. I vaguely recall a strange edge case in which the active window was not necessarily the foreground window. Or perhaps I've simply gone mad. – Mike Strobel Aug 11 '10 at 16:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.