Keyboard.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: Keyboard.h ///////////////////////////////////////////////////////////
  24. //-----------------------------------------------------------------------------
  25. //
  26. // Westwood Studios Pacific.
  27. //
  28. // Confidential Information
  29. // Copyright (C) 2001 - All Rights Reserved
  30. //
  31. //-----------------------------------------------------------------------------
  32. //
  33. // Project: RTS3
  34. //
  35. // File name: Keyboard.h
  36. //
  37. // Created: Mike Morrison, 1995
  38. // Colin Day, June 2001
  39. //
  40. // Desc: Basic keyboard
  41. //
  42. //-----------------------------------------------------------------------------
  43. ///////////////////////////////////////////////////////////////////////////////
  44. #pragma once
  45. #ifndef __KEYBOARD_H_
  46. #define __KEYBOARD_H_
  47. // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
  48. // USER INCLUDES //////////////////////////////////////////////////////////////
  49. #include "Common/SubsystemInterface.h"
  50. #include "GameClient/KeyDefs.h"
  51. #include "Lib/BaseType.h"
  52. // FORWARD REFERENCES /////////////////////////////////////////////////////////
  53. ///////////////////////////////////////////////////////////////////////////////
  54. // TYPE DEFINITIONS ///////////////////////////////////////////////////////////
  55. ///////////////////////////////////////////////////////////////////////////////
  56. // KeyboardIO -----------------------------------------------------------------
  57. /** Holds a single keyboard event */
  58. //-----------------------------------------------------------------------------
  59. struct KeyboardIO
  60. {
  61. enum StatusType
  62. {
  63. STATUS_UNUSED = 0x00, // Key has not been used
  64. STATUS_USED = 0x01 // Key has been eaten
  65. };
  66. UnsignedByte key; // key data
  67. UnsignedByte status; // StatusType, above
  68. UnsignedShort state; // KEY_STATE_* in KeyDefs.h
  69. UnsignedInt sequence; // sequence info from DirectX used for order
  70. }; // end KeyboardIO
  71. // class Keyboard =============================================================
  72. /** Keyboard singleton to interface with the keyboard */
  73. //=============================================================================
  74. class Keyboard : public SubsystemInterface
  75. {
  76. enum { KEY_REPEAT_DELAY = 10 };
  77. public:
  78. Keyboard( void );
  79. virtual ~Keyboard( void );
  80. // you may extend the functionanilty of these for your device
  81. virtual void init( void ); /**< initialize the keyboard, only extend this
  82. functionality, do not replace */
  83. virtual void reset( void ); ///< Reset keyboard system
  84. virtual void update( void ); /**< gather current state of all keys, extend
  85. this functionality, do not replace */
  86. virtual Bool getCapsState( void ) = 0; ///< get state of caps lock key, return TRUE if down
  87. virtual void createStreamMessages( void ); /**< given state of device, create
  88. messages and put them on the
  89. stream for the raw state. */
  90. // simplified versions where the caller doesn't care which key type was pressed.
  91. Bool isShift();
  92. Bool isCtrl();
  93. Bool isAlt();
  94. Int getModifierFlags() { return m_modifiers; }
  95. // access methods for key data
  96. void resetKeys( void ); ///< reset the state of the keys
  97. KeyboardIO *getFirstKey( void ); ///< get first key ready for processing
  98. void setKeyStatusData( UnsignedByte key,
  99. KeyboardIO::StatusType data ); ///< set key status
  100. WideChar translateKey( WideChar keyCode ); ///< translte key code to printable UNICODE char
  101. WideChar getPrintableKey( UnsignedByte key, Int state );
  102. enum { MAX_KEY_STATES = 3};
  103. protected:
  104. /** get the key data for a single key, KEY_NONE should be returned when
  105. no key data is available to get anymore, you must implement this for your device */
  106. virtual void getKey( KeyboardIO *key ) = 0;
  107. // internal methods to update the key states
  108. void initKeyNames( void ); ///< initialize the key names table
  109. void updateKeys( void ); ///< update the state of our key data
  110. Bool checkKeyRepeat( void ); ///< check for repeating keys
  111. UnsignedByte getKeyStatusData( UnsignedByte key ); ///< get key status
  112. Bool getKeyStateBit( UnsignedByte key, Int bit ); ///< get key state bit
  113. UnsignedInt getKeySequenceData( UnsignedByte key ); ///< get key sequence
  114. void setKeyStateData( UnsignedByte key, UnsignedByte data ); ///< get key state
  115. UnsignedShort m_modifiers;
  116. // internal keyboard data members
  117. //Bool m_capsState; // 1 if caps lock is on
  118. //Bool m_shiftState; // 1 if either shift key is pressed
  119. //Bool m_shift2State; // 1 if secondary shift key is pressed
  120. //Bool m_lShiftState; // 1 if left state is down
  121. //Bool m_rShiftState; // 1 if right shift is down
  122. //Bool m_lControlState; // 1 if left control is down
  123. //Bool m_rControlState; // 1 if right control is down
  124. //Bool m_lAltState; // 1 if left alt is down
  125. //Bool m_rAltState; // 1 if right alt is down
  126. UnsignedByte m_shift2Key; // what key is the secondary shift key
  127. enum { NUM_KEYS = 256 };
  128. KeyboardIO m_keys[ NUM_KEYS ]; ///< the keys
  129. KeyboardIO m_keyStatus[ NUM_KEYS ]; ///< the key status flags
  130. enum { KEY_NAMES_COUNT = 256 };
  131. struct
  132. {
  133. WideChar stdKey;
  134. WideChar shifted;
  135. WideChar shifted2;
  136. } m_keyNames[ KEY_NAMES_COUNT ];
  137. UnsignedInt m_inputFrame; ///< frame input was gathered on
  138. }; // end Keyboard
  139. // INLINING ///////////////////////////////////////////////////////////////////
  140. // EXTERNALS //////////////////////////////////////////////////////////////////
  141. extern Keyboard *TheKeyboard;
  142. #endif // __KEYBOARD_H_