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.

  • \$\begingroup\$ 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? \$\endgroup\$ – Mike Strobel Aug 9 '10 at 20:40
  • \$\begingroup\$ Since these are not game development exclusive topics, this question belongs at Stack Overflow stackoverflow.com where you should get a much better response. \$\endgroup\$ – Ricket Aug 9 '10 at 20:41
  • \$\begingroup\$ Im using GetAsyncKeyState for input rather that glut. \$\endgroup\$ – 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()
|improve this answer|||||
  • \$\begingroup\$ If you are ok with windows specific code, this would work fine i guess \$\endgroup\$ – 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.

|improve this answer|||||
  • \$\begingroup\$ 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. \$\endgroup\$ – Mike Strobel Aug 11 '10 at 16:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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