Original Post
Hi!
Im running in windowed mode and when i switch to another window and back the game input stops working.
This is my DI setup and call:
HRESULT CKeyboard::Init( HWND hWnd )
{
HRESULT hResult = 0;
if( !g_pDI ) return E_FAIL;
RELEASEDID( m_pDIDevice );
hResult = g_pDI->CreateDevice( GUID_SysKeyboard, &m_pDIDevice, NULL );
if( FAILED( hResult ) )
{
OutputDebugString( "Failed to create key device!\n" );
return E_FAIL;
}
hResult = m_pDIDevice->SetDataFormat( &c_dfDIKeyboard );
if( FAILED( hResult ) )
{
OutputDebugString( "Unable to set the keyboard data format!\n" );
return E_FAIL;
}
hResult = m_pDIDevice->SetCooperativeLevel( hWnd,
DISCL_FOREGROUND |
DISCL_NONEXCLUSIVE );
if( FAILED( hResult ) )
{
OutputDebugString( "Unable to set cooperative level for the keyboard!\n" );
return E_FAIL;
}
hResult = m_pDIDevice->Acquire();
if( FAILED( hResult ) )
{
OutputDebugString( "Unable to acquire the keyboard!\n" );
return E_FAIL;
}
m_bInitialized = TRUE;
return S_OK;
}
BOOL CKeyboard::KeyDown( int key )
{
HRESULT hResult = 0;
if( !m_bInitialized ) return FALSE;
hResult = m_pDIDevice->GetDeviceState( sizeof( m_KeyBuffer ), &m_KeyBuffer );
if( FAILED( hResult ) )
{
if( hResult == DIERR_INPUTLOST )
{
while( hResult == DIERR_INPUTLOST )
hResult = m_pDIDevice->Acquire();
if( SUCCEEDED( hResult ) )
hResult = m_pDIDevice->GetDeviceState( sizeof( m_KeyBuffer ),
&m_KeyBuffer );
else return FALSE;
}
else return FALSE;
}
if ( m_KeyBuffer[key] & 0x80 ) return TRUE;
else return FALSE;
}
Just cant find whats wrong.....