Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 21, 2008, 9:07:08 PM (16 years ago)
Author:
rgrieder
Message:
  • merged input branch back to trunk
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/ois/win32/Win32KeyBoard.cpp

    r1219 r1349  
    105105        DWORD entries = KEYBOARD_DX_BUFFERSIZE;
    106106        HRESULT hr;
     107        //Only one keyboard allowed per app, so static is ok
     108        static bool verifyAfterAltTab = false;
    107109
    108110        hr = mKeyboard->GetDeviceData( sizeof(DIDEVICEOBJECTDATA), diBuff, &entries, 0 );
     
    110112        {
    111113                hr = mKeyboard->Acquire();
     114                if (hr == E_ACCESSDENIED)
     115                        verifyAfterAltTab = true;
     116
    112117                while( hr == DIERR_INPUTLOST )
    113118                        hr = mKeyboard->Acquire();
     119
    114120                return;
    115121        }
     
    121127        for(unsigned int i = 0; i < entries; ++i )
    122128        {
    123                 //If the mListener returns false, that means that we are probably deleted...
     129                //If the listener returns false, that means that we are probably deleted...
    124130                //send no more events and just leave as the this pointer is invalid now...
    125131                bool ret = true;
     
    159165                if(ret == false)
    160166                        break;
     167        }
     168
     169        // If a lost device/access denied was detected, recover gracefully with new events
     170        if(verifyAfterAltTab)
     171        {
     172                bool ret = true;
     173               
     174                //Copy old buffer to temp location to compare against
     175                unsigned char keyBufferCopy[256];
     176                memcpy(keyBufferCopy, KeyBuffer, 256);
     177
     178                //Update new state
     179                _read();
     180
     181                for (unsigned i = 0; i < 256; i++)
     182                {
     183                        if (keyBufferCopy[i] != KeyBuffer[i])
     184                        {
     185                                if (mListener)
     186                                {
     187                                        if (KeyBuffer[i])
     188                                                ret = mListener->keyPressed( KeyEvent( this, (KeyCode)i, _translateText((KeyCode)i) ) );
     189                                        else
     190                                                ret = mListener->keyReleased( KeyEvent( this, (KeyCode)i, 0 ) );
     191                                }
     192                        }
     193
     194                        //If user returned false from callback, return immediately
     195                        if(ret == false)
     196                                return;
     197                }
     198
     199                verifyAfterAltTab = false;
    161200        }
    162201}
     
    243282
    244283//--------------------------------------------------------------------------------------------------//
    245 bool Win32Keyboard::isKeyDown( KeyCode key )
     284bool Win32Keyboard::isKeyDown( KeyCode key ) const
    246285{
    247286        return (KeyBuffer[key] & 0x80) != 0;
     
    272311
    273312//--------------------------------------------------------------------------------------------------//
    274 void Win32Keyboard::copyKeyStates( char keys[256] )
     313void Win32Keyboard::copyKeyStates( char keys[256] ) const
    275314{
    276315        for(int i = 0; i < 256; ++i)
Note: See TracChangeset for help on using the changeset viewer.