Jump to content
  • Advertisement
Sign in to follow this  
jujumbura

DirectInput problem

This topic is 4761 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello folks, So I've got this little problem in my C++ app with DirectInput. When I set the cooperative level of my device to "FOREGROUND", I never get keystrokes. In fact, any calls to getDeviceState() return an error. However, if I set the cooperative level to "BACKGROUND", I get keystrokes just fine. "FOREGROUND" is defined as the device only gets input when it is in the foreground, whereas "BACKGROUND" gets input all the time. It sounds to me like my app is not getting focus properly perhaps? But I've tried typing keys when I'm the topmost window, and highlighted. Is there something I need to do within my app to "register" myself as having the foreground? Handle some message from the Windows message pump perhaps? Any advice is greatly appreciated! Thanks jujumbura

Share this post


Link to post
Share on other sites
Advertisement
If you specifiy DISCL_FOREGROUND | DISCL_NONEXCLUSIVE, then you will need to Acquire the device on app activation. If you try to acquire the device before your window is up and displayed in the foreground, the acquire will fail.

You can get around this by doing an Acquire() call whenever getDeviceState() fails. If the Acquire() call fails, just return. Otherwise, attempt the getDeviceState() call again. If the app isn't activated, the acquire will fail and you don't need to continue. If it is activated, the acquire should succeed and you can continue.

An alternative would be to handle the WM_ACTIVATE message and acquire your device(s) when the wParam is not WA_INACTIVE.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!