Archived

This topic is now archived and is closed to further replies.

hajkr

problem with reacquiring the keyboarddevice...

Recommended Posts

i have made a standard keyboard device with directx8 and it works great until another application gets the focus and i then my application gets the focus back and i want to reacquire the device when i receive the WM_ACTIVE message with m_pDevice->Acquire( ). But when the app gets the focus back it return an device-error. Does anybody have an solution ?

Share this post


Link to post
Share on other sites
Have you tried different cooperative levels for your keyboard? You might want to try setting it to non exclusive and in the background.





------------------------------
"I''m a decorated astronaut, I don''t make those kind of mistakes."
"Oh now wait a minute. Look I''ll show ya. I''ll enter the same calculations using what we like to call ''The Right Way''."

-Rem
Zirem Software

Share this post


Link to post
Share on other sites
I think your problem is that your aquiring the keyboard when your app loses focus and regains focus.

Try acquring the keyboard when you receive focus, and release it when you lose focus.

Personally, my DirectX lib doesn''t have this problem



------------------------------
"I''m a decorated astronaut, I don''t make those kind of mistakes."
"Oh now wait a minute. Look I''ll show ya. I''ll enter the same calculations using what we like to call ''The Right Way''."

-Rem
Zirem Software

Share this post


Link to post
Share on other sites
As far as I know, it doesn''t.



------------------------------
"I''m a decorated astronaut, I don''t make those kind of mistakes."
"Oh now wait a minute. Look I''ll show ya. I''ll enter the same calculations using what we like to call ''The Right Way''."

-Rem
Zirem Software

Share this post


Link to post
Share on other sites
It returns DIERR_NOTACQUIRED, when i call "GetDeviceState()"
But i''m acquierung it when the WM_ACTIVE-Message arives and there it returns no error.
So I don''t understand why it can not be acquired.

Share this post


Link to post
Share on other sites
This is unlikely, but it could just be your development machine. Hit Ctrl-Alt-Del to get the task list and close all unrelated processes. There might be something running there that has taken control of the keyboard.

Superpig
- saving pigs from untimely fates

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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 );
}



Share this post


Link to post
Share on other sites