Sign in to follow this  
jujumbura

DirectInput problem

Recommended Posts

jujumbura    209
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
Dave Hunt    4872
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this