problem with reacquiring the keyboarddevice...

Started by
11 comments, last by hajkr 22 years, 5 months ago
ok i did closed all that apps, but it didn''t help.
can anybody say exactly how and when an device is reacquired ?
If you want i can mail you my code and you can look at it.
Advertisement
Posting the code would probably help.

Is your app using multiple threads? AFAIK you have to use the device from the same thread you set the coop-level in. Not doing so might return an OTHERAPPHASPRIO error.

Superpig
- saving pigs from untimely fates
- sleeps in a ham-mock at www.thebinaryrefinery.cjb.net

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

ok here is my code:

First the code that returns the data:

HRESULT CMyInput::GetKeyboardInput( )
{
HRESULT hr;

if( FAILED( hr = m_lpKeyboardDevice->GetDeviceState( sizeof( m_cKeyboardbuffer ),
(LPVOID) &m_cKeyboardbuffer ) ) )
{
// If input is lost try to reacquire the device
if( hr == DIERR_INPUTLOST )
{
// if the device can''t be reacquired then return error
if( FAILED( hr = m_lpKeyboardDevice->Acquire( ) ) )
return hr;

if( FAILED( hr = m_lpKeyboardDevice->GetDeviceState( sizeof( m_cKeyboardbuffer ),
(LPVOID) &m_cKeyboardbuffer ) ) )
{
return hr;
}
}

// return error
return hr;
}

return S_OK;
}

Here the code that creates the keyboard device:
( I have used the coopflags NONEXCLUSIVE and FOREGROUND )

HRESULT CMyInput::CreateKeyboardDevice( HWND hwnd, DWORD coopflags )
{
HRESULT hr;

if( FAILED( hr = m_lpDI->CreateDevice( GUID_SysKeyboard, &m_lpKeyboardDevice, NULL ) ) )
return hr;

if( FAILED( hr = m_lpKeyboardDevice->SetDataFormat( &c_dfDIKeyboard ) ) )
return hr;

if( FAILED( hr = m_lpKeyboardDevice->SetCooperativeLevel( hwnd, coopflags ) ) )
{
return hr;
}

if( FAILED( hr = m_lpKeyboardDevice->Acquire( ) ) )
return hr;

// Set Keyboard as a valid and usable Device
if( ( m_iUsedDevices & MYINPUT_KEYBOARD ) == 0 )
m_iUsedDevices += MYINPUT_KEYBOARD;

return S_OK;
}

Here ic the messageproc:

LRESULT CD3DMyApplication::MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
HRESULT hr;

switch( uMsg )
{
case WM_EXITMENULOOP:
case WM_EXITSIZEMOVE:
if( ( m_pInput->m_iUsedDevices & MYINPUT_KEYBOARD ) )
if( FAILED( hr = m_pInput->SetKeyboardAcquire( TRUE ) ) )
DisplayErrorMsg( hr, MSGERR_APPMUSTEXIT );
break;

case WM_ACTIVATE:
if( ! ( WA_INACTIVE == wParam ) && ( m_pInput->m_iUsedDevices & MYINPUT_KEYBOARD ) )
if( FAILED( hr = m_pInput->SetKeyboardAcquire( TRUE ) ) )
DisplayErrorMsg( hr, MSGERR_APPMUSTEXIT );
break;
}

return CD3DApplication::MsgProc( hWnd, uMsg, wParam, lParam );
}



This topic is closed to new replies.

Advertisement