home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 27 / IOPROG_27.ISO / SOFT / CDX.ZIP / Src / Cdi / Keyboard.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-09-14  |  2.1 KB  |  65 lines

  1. //////////////////////////////////////////////////////////////////////////////////
  2. // Project Name: [ CDI Class Library - CDI.lib ]
  3. // Author:       [ Dan Farley - 97308096@brookes.ac.uk ]
  4. // Source File:  [ CDI_Keyboard Implementation ]
  5. // Revision:     [ 1.6 ]
  6. //////////////////////////////////////////////////////////////////////////////////
  7. #include "CDI.h"
  8.  
  9. //////////////////////////////////////////////////////////////////////////////////
  10. // CDI_Keyboard Constructor
  11. //////////////////////////////////////////////////////////////////////////////////
  12. CDI_Keyboard::CDI_Keyboard(void)
  13. {
  14.     m_Device = NULL;
  15.     m_bActive = FALSE;
  16. }
  17.  
  18. //////////////////////////////////////////////////////////////////////////////////
  19. // CDI_Keyboard Destructor
  20. //////////////////////////////////////////////////////////////////////////////////
  21. CDI_Keyboard::~CDI_Keyboard(void)
  22. {
  23.     m_Device->Unacquire();
  24.     RELEASE(m_Device);
  25. }
  26.  
  27. //////////////////////////////////////////////////////////////////////////////////
  28. // CDI_Keyboard Create
  29. //////////////////////////////////////////////////////////////////////////////////
  30. HRESULT CDI_Keyboard::Create(CDI_Input* input, void* hwnd)
  31. {
  32.     HRESULT rval;
  33.     LPDIRECTINPUTDEVICE lpDID = NULL;
  34.  
  35.     // Create the keyboard device
  36.     rval = input->GetDI()->CreateDevice(GUID_SysKeyboard, &lpDID, NULL);
  37.     if(rval == DI_OK)
  38.     {
  39.         rval = lpDID->QueryInterface(IID_IDirectInputDevice2, (LPVOID*)&m_Device);
  40.         if(rval != DI_OK) return rval;
  41.  
  42.         RELEASE(lpDID);
  43.  
  44.         m_Device->SetDataFormat(&c_dfDIKeyboard);
  45.         m_Device->SetCooperativeLevel(hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
  46.  
  47.         rval = m_Device->Acquire();
  48.         if(rval != DI_OK) return rval;
  49.  
  50.         m_bActive = TRUE;
  51.     }
  52.  
  53.     return rval;
  54. }
  55.  
  56. //////////////////////////////////////////////////////////////////////////////////
  57. // CDI_Keyboard Update
  58. //////////////////////////////////////////////////////////////////////////////////
  59. void CDI_Keyboard::Update(void)
  60. {
  61.     if(m_bActive)
  62.         if(m_Device->GetDeviceState(256, &m_Keys) == (DIERR_INPUTLOST | DIERR_NOTACQUIRED))
  63.             m_Device->Acquire();
  64. }
  65.