Skip to main content
GameDev.net gamedev.net
🔒 Locked

Some Direct Input problems

Started by russian-bear Apr 9, 2002 at 10:35 AM 0 replies 100+ views
Original Post
russian-bear
russian-bear
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.....
< There are no stupid questions, only stupid answers! >
russian-bear
russian-bear
Ahhh! I found the problem....
I had to Acquire the keyboard in VW_ACTIVATE message....

< There are no stupid questions, only stupid answers! >

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.