Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
1.5 KiB

  1. //====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef KEYREPEAT_H
  7. #define KEYREPEAT_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include <vgui_controls/Panel.h>
  12. namespace vgui
  13. {
  14. enum KEYREPEAT_ALIASES
  15. {
  16. KR_ALIAS_UP,
  17. KR_ALIAS_DOWN,
  18. KR_ALIAS_LEFT,
  19. KR_ALIAS_RIGHT,
  20. FM_NUM_KEYREPEAT_ALIASES,
  21. };
  22. class CKeyRepeatHandler
  23. {
  24. public:
  25. CKeyRepeatHandler()
  26. {
  27. Reset();
  28. for ( int i = 0; i < FM_NUM_KEYREPEAT_ALIASES; i++ )
  29. {
  30. m_flRepeatTimes[i] = 0.16;
  31. }
  32. }
  33. void Reset( void ) { memset( m_bAliasDown, 0, sizeof(bool) * FM_NUM_KEYREPEAT_ALIASES ); m_bHaveKeyDown = false; }
  34. void KeyDown( vgui::KeyCode code );
  35. void KeyUp( vgui::KeyCode code );
  36. vgui::KeyCode KeyRepeated( void );
  37. void SetKeyRepeatTime( vgui::KeyCode code, float flRepeat );
  38. private:
  39. int GetIndexForCode( vgui::KeyCode code )
  40. {
  41. switch ( code )
  42. {
  43. case KEY_XBUTTON_DOWN:
  44. case KEY_XSTICK1_DOWN:
  45. return KR_ALIAS_DOWN; break;
  46. case KEY_XBUTTON_UP:
  47. case KEY_XSTICK1_UP:
  48. return KR_ALIAS_UP; break;
  49. case KEY_XBUTTON_LEFT:
  50. case KEY_XSTICK1_LEFT:
  51. return KR_ALIAS_LEFT; break;
  52. case KEY_XBUTTON_RIGHT:
  53. case KEY_XSTICK1_RIGHT:
  54. return KR_ALIAS_RIGHT; break;
  55. default:
  56. break;
  57. }
  58. return -1;
  59. }
  60. private:
  61. bool m_bAliasDown[FM_NUM_KEYREPEAT_ALIASES];
  62. float m_flRepeatTimes[FM_NUM_KEYREPEAT_ALIASES];
  63. float m_flNextKeyRepeat;
  64. bool m_bHaveKeyDown;
  65. };
  66. } // namespace vgui
  67. #endif // KEYREPEAT_H