Sign in to follow this  
MrDoomMaster

DirectInput Aquire() Fails

Recommended Posts

MrDoomMaster    103
If the window is not visible or the active window at the time I am initializing the Keyboard and Mouse as input devices in DirectInput, then Aquire() will fail when I call it on the mouse object. I don't know why this happens. It works perfectly fine otherwise. For example, if I step through the DirectInput initialization process via the Visual Studio debugger, it will fail because the window is not active/visible. The error return is DI_OK, but FAILED() says it failed. Below is my setup process, in case you're curious of my code:

        memset(m_KeyTap, 0, 256);

        CSAFECALL(DirectInput8Create(m_Window->GetInstance(), DIRECTINPUT_VERSION,
            IID_IDirectInput8, (void**)&m_Object, NULL));

        // Initialize Keyboard
        CSAFECALL(m_Object->CreateDevice(GUID_SysKeyboard, &m_Keyboard, NULL));
        CSAFECALL(m_Keyboard->SetDataFormat(&c_dfDIKeyboard));
        CSAFECALL(m_Keyboard->SetCooperativeLevel(m_Window->GetWindowHandle(), DISCL_NONEXCLUSIVE | DISCL_BACKGROUND));
        CSAFECALL(m_Keyboard->Acquire());

        // Initialize Mouse
        CSAFECALL(m_Object->CreateDevice(GUID_SysMouse, &m_Mouse, NULL));
        CSAFECALL(m_Mouse->SetDataFormat(&c_dfDIMouse));
        CSAFECALL(m_Mouse->SetCooperativeLevel(m_Window->GetWindowHandle(), DISCL_NONEXCLUSIVE | DISCL_BACKGROUND));
        CSAFECALL(m_Mouse->Acquire());

Share this post


Link to post
Share on other sites
Promit    13246
I think that's just how things are. You can't acquire the device from a hidden window. Anyway, DI is going away soon, so it's recommended that you switch to standard Win32 API calls for keyboard and mouse, and only use DI for joysticks and controllers and stuff.

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