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.

141 lines
3.0 KiB

  1. //====== Copyright � 1996-2004, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "movieobjects/dmekeyboardinput.h"
  7. #include "movieobjects_interfaces.h"
  8. #include "datamodel/dmelementfactoryhelper.h"
  9. #include "vgui/iinput.h"
  10. #include "vgui/keycode.h"
  11. #include "tier3/tier3.h"
  12. #include "tier0/dbg.h"
  13. // memdbgon must be the last include file in a .cpp file!!!
  14. #include "tier0/memdbgon.h"
  15. //-----------------------------------------------------------------------------
  16. // global list of all keys supported
  17. //-----------------------------------------------------------------------------
  18. struct KeyInfo
  19. {
  20. vgui::KeyCode code;
  21. const char *str;
  22. };
  23. const uint g_nKeys = 48;
  24. const KeyInfo g_keyInfo[ g_nKeys ] =
  25. {
  26. { KEY_0, "0" },
  27. { KEY_1, "1" },
  28. { KEY_2, "2" },
  29. { KEY_3, "3" },
  30. { KEY_4, "4" },
  31. { KEY_5, "5" },
  32. { KEY_6, "6" },
  33. { KEY_7, "7" },
  34. { KEY_8, "8" },
  35. { KEY_9, "9" },
  36. { KEY_A, "A" },
  37. { KEY_B, "B" },
  38. { KEY_C, "C" },
  39. { KEY_D, "D" },
  40. { KEY_E, "E" },
  41. { KEY_F, "F" },
  42. { KEY_G, "G" },
  43. { KEY_H, "H" },
  44. { KEY_I, "I" },
  45. { KEY_J, "J" },
  46. { KEY_K, "K" },
  47. { KEY_L, "L" },
  48. { KEY_M, "M" },
  49. { KEY_N, "N" },
  50. { KEY_O, "O" },
  51. { KEY_P, "P" },
  52. { KEY_Q, "Q" },
  53. { KEY_R, "R" },
  54. { KEY_S, "S" },
  55. { KEY_T, "T" },
  56. { KEY_U, "U" },
  57. { KEY_V, "V" },
  58. { KEY_W, "W" },
  59. { KEY_X, "X" },
  60. { KEY_Y, "Y" },
  61. { KEY_Z, "Z" },
  62. { KEY_F1, "F1" },
  63. { KEY_F2, "F2" },
  64. { KEY_F3, "F3" },
  65. { KEY_F4, "F4" },
  66. { KEY_F5, "F5" },
  67. { KEY_F6, "F6" },
  68. { KEY_F7, "F7" },
  69. { KEY_F8, "F8" },
  70. { KEY_F9, "F9" },
  71. { KEY_F10, "F10" },
  72. { KEY_F11, "F11" },
  73. { KEY_F12, "F12" },
  74. };
  75. //-----------------------------------------------------------------------------
  76. // Expose this class to the scene database
  77. //-----------------------------------------------------------------------------
  78. IMPLEMENT_ELEMENT_FACTORY( DmeKeyboardInput, CDmeKeyboardInput );
  79. //-----------------------------------------------------------------------------
  80. // Purpose:
  81. //-----------------------------------------------------------------------------
  82. void CDmeKeyboardInput::OnConstruction()
  83. {
  84. m_keys = new CDmaVar< bool >[ g_nKeys ];
  85. for ( uint ki = 0; ki < g_nKeys; ++ki )
  86. {
  87. m_keys[ ki ].Init( this, g_keyInfo[ ki ].str );
  88. }
  89. }
  90. void CDmeKeyboardInput::OnDestruction()
  91. {
  92. delete[] m_keys;
  93. }
  94. bool CDmeKeyboardInput::IsDirty()
  95. {
  96. for ( uint ki = 0; ki < g_nKeys; ++ki )
  97. {
  98. if ( m_keys[ ki ].Get() != GetKeyStatus( ki ) )
  99. return true;
  100. }
  101. return false;
  102. }
  103. void CDmeKeyboardInput::Operate()
  104. {
  105. for ( uint ki = 0; ki < g_nKeys; ++ki )
  106. {
  107. m_keys[ ki ].Set( GetKeyStatus( ki ) );
  108. }
  109. }
  110. void CDmeKeyboardInput::GetInputAttributes( CUtlVector< CDmAttribute * > &attrs )
  111. {
  112. }
  113. void CDmeKeyboardInput::GetOutputAttributes( CUtlVector< CDmAttribute * > &attrs )
  114. {
  115. for ( uint ki = 0; ki < g_nKeys; ++ki )
  116. {
  117. attrs.AddToTail( m_keys[ ki ].GetAttribute() );
  118. }
  119. }
  120. bool CDmeKeyboardInput::GetKeyStatus( uint ki )
  121. {
  122. return g_pVGuiInput->IsKeyDown( g_keyInfo[ ki ].code );
  123. }