void WINAPI ProcessKBInput(HWND hWnd)
{
if (KeyInit==true)
{
if (hWnd != GetActiveWindow())
{
//MessageBox(NULL, "Not Active Window!", "Start", MB_OK);
return;
}
hr = g_lpDIDevice->GetDeviceState(sizeof(keybuffer),(LPVOID)&keybuffer);
if FAILED(hr)
{
SetAcquire(hWnd);
// If it failed, the device has probably been lost.
// Check for (hr == DIERR_INPUTLOST)
// and attempt to reacquire it here.
}
if (KEYDOWN(keybuffer, DIK_ESCAPE))
{
PostQuitMessage(0);
//exit(NULL);
return;
}
if (KEYUP(keybuffer, DIK_ESCAPE))
{
//PostQuitMessage(0);
//exit(NULL);
return;
}
}
return;
}
//-----------------------------------------------------------------------------
// Name: OnMouseInput()
// Desc: Gets the Mouse Input
//-----------------------------------------------------------------------------
VOID OnMouseInput(HWND hWnd)
{
if (MouseInit==true)
{
if (hWnd != GetActiveWindow())
{
//MessageBox(NULL, "Not Active Window!", "Start", MB_OK);
return;
}
hr = g_pMouse->GetDeviceState(sizeof(mousebuffer),(LPVOID)&mousebuffer);
if FAILED(hr)
{
SetAcquire(hWnd);
// If it failed, the device has probably been lost.
// Check for (hr == DIERR_INPUTLOST)
// and attempt to reacquire it here.
}
if (mousebuffer.rgbButtons[0] & 0x80)
{
PostQuitMessage(0);
}
}
return;
}
dinput doesn't work
Hi everyone, the last couple of days I been trying to learn what some say is the most basic part of directx, dinput. Unfortunally, I have not been successfull. So far I initialize the directinput device, mouse and keyboard with no problem. I can even see that it works because if I change the mouse for exclusive to non exclusive, the mouse disappearse. The problem is I can't seem to retreive the data from either one of them. this is what I have written to retreive data:
I hope is not to long to read or to figure out. Maybe I'm just calling it in the wrong place. But when i call it it does go in the respective routines but it does not fill the buffer variable.
Thank you in advance.
[Edited by - Coder on April 26, 2005 10:46:41 PM]
A couple of things: you need to clear your keyBuffer to all zeros each time and you need your re-acquire loop to be working, it should look something like this:
HRESULT hr=m_diKeyboardDevice->GetDeviceState( sizeof(keys), keys );if (FAILED(hr)){ // If input is lost then acquire and keep trying until we get it back hr=m_diKeyboardDevice->Acquire(); while( hr == DIERR_INPUTLOST ) { hr = m_diKeyboardDevice->Acquire(); } // Now get them again m_diKeyboardDevice->GetDeviceState( sizeof(keys), keys );}
I'm sorry, the SetAcquire loop is like this..
[Edited by - mvtapia on April 26, 2005 7:36:48 PM]
void SetAcquire(HWND hWnd){ if (hWnd != GetActiveWindow()) { MessageBox(NULL, "Not Active Window!", "Start", MB_OK); return; }if (KeyInit==true){ hr = g_lpDIDevice->GetDeviceState(sizeof(keybuffer),(LPVOID)&keybuffer); if FAILED(hr) { if (hr==DIERR_NOTACQUIRED || hr==DIERR_INPUTLOST) { while (hr == DIERR_INPUTLOST || hr==DIERR_NOTACQUIRED) // if not acquired hr = g_lpDIDevice->Acquire(); // get it back } else // otherwise it was some other error return; // If it failed, the device has probably been lost. // Check for (hr == DIERR_INPUTLOST) // and attempt to reacquire it here. } }if(MouseInit==true){ hr = g_pMouse->GetDeviceState(sizeof(mousebuffer),(LPVOID)&mousebuffer); if FAILED(hr) { if (hr==DIERR_NOTACQUIRED || hr==DIERR_INPUTLOST) { while (hr == DIERR_INPUTLOST || hr==DIERR_NOTACQUIRED) // if not acquired hr = g_pMouse->Acquire(); // get it back } else // otherwise it was some other error return; // If it failed, the device has probably been lost. // Check for (hr == DIERR_INPUTLOST) // and attempt to reacquire it here. } }return;}
[Edited by - mvtapia on April 26, 2005 7:36:48 PM]
To post source code, you can use the [source] [/source] tags [smile]. You can edit your posts, so you can get more help [wink].
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement