KbdManager.cpp
上传用户:royluo
上传日期:2007-01-05
资源大小:1584k
文件大小:3k
源码类别:

游戏

开发平台:

Visual C++

  1. /*****************************************************************************
  2. *                                                                             
  3. *   KbdManager.cpp                                                            
  4. *                                                                             
  5. *   Electrical Engineering Faculty - Software Lab                             
  6. *   Spring semester 1998                                                      
  7. *                                                                             
  8. *   Tanks game                                                                
  9. *                                                                             
  10. *   Module description: The keyboard manager holds the player control keys in
  11. *                       use. It allows the user to assign his own keys to the
  12. *                       different tank actions, check for conflicts, and store
  13. *                       the table for future use in the registry file.
  14. *                                                                             
  15. *   Authors: Eran Yariv - 28484475                                           
  16. *            Moshe Zur  - 24070856                                           
  17. *                                                                            
  18. *                                                                            
  19. *   Date: 23/09/98                                                           
  20. *                                                                            
  21. ******************************************************************************/
  22. #include <stdafx.h>
  23. #include <KbdManager.h>
  24. #include "keymappingdlg.h"
  25. void
  26. CKbdManager::SetKbdMapping()
  27. {
  28.     // Make a copy of current set of keys, and pass it to dlg:
  29.     CKeysTable NewKeys = m_Keys;
  30.     // Create Keys configuration dlg:
  31. CKeyMappingDlg dlg(&NewKeys);
  32. int nResponse = dlg.DoModal();
  33. if (nResponse == IDOK)  // Replace the current settings with the new ones:
  34. {
  35.         m_Keys = NewKeys;
  36. }
  37. }
  38. /*------------------------------------------------------------------------------
  39.   Function: RefreshManouverSet
  40.   Purpose:  Refresh the local tank's maneuver set after each use, to deal with
  41.             situation of focus lost of the main game dialog.
  42.   Input:    None.
  43.   Output:   None.
  44.   Remarks:  When the game loose it's focus, the WM_KEY_UP message may be missed,
  45.             thus causing the tank to repeat it's last maneuver set. To eliminate
  46.             this phenomena, we check the key board state after every use of the
  47.             maneuver set by the local tank.
  48. ------------------------------------------------------------------------------*/
  49. void
  50. CKbdManager::RefreshManouverSet()
  51. {
  52.     ASSERT(m_pManouverSet);
  53.     for (int i = 0; i < 8; i++)
  54.     {
  55.         UINT uKeyCode = m_Keys.GetKey(i);
  56.         if (! GetAsyncKeyState(uKeyCode))   // Key is up or nother window got the kbd input
  57.             m_pManouverSet -> UnsetBit (i);
  58.     }
  59. }