Keyboard.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #pragma once
  5. class ApplicationWindow;
  6. enum class EKey
  7. {
  8. Invalid,
  9. Unknown,
  10. A,
  11. B,
  12. C,
  13. D,
  14. E,
  15. F,
  16. G,
  17. H,
  18. I,
  19. J,
  20. K,
  21. L,
  22. M,
  23. N,
  24. O,
  25. P,
  26. Q,
  27. R,
  28. S,
  29. T,
  30. U,
  31. V,
  32. W,
  33. X,
  34. Y,
  35. Z,
  36. Num0,
  37. Num1,
  38. Num2,
  39. Num3,
  40. Num4,
  41. Num5,
  42. Num6,
  43. Num7,
  44. Num8,
  45. Num9,
  46. Space,
  47. Comma,
  48. Period,
  49. Escape,
  50. LShift,
  51. RShift,
  52. LControl,
  53. RControl,
  54. LAlt,
  55. RAlt,
  56. Left,
  57. Right,
  58. Up,
  59. Down,
  60. Return,
  61. NumKeys,
  62. };
  63. /// Keyboard interface class which keeps track on the status of all keys and keeps track of the list of keys pressed.
  64. class Keyboard
  65. {
  66. public:
  67. /// Constructor
  68. Keyboard() = default;
  69. virtual ~Keyboard() = default;
  70. /// Initialization / shutdown
  71. virtual bool Initialize(ApplicationWindow *inWindow) = 0;
  72. virtual void Shutdown() = 0;
  73. /// Update the keyboard state
  74. virtual void Poll() = 0;
  75. /// Checks if a key is pressed or not
  76. virtual bool IsKeyPressed(EKey inKey) const = 0;
  77. /// Checks if a key is pressed and was not pressed the last time this function was called (state is stored in ioPrevState)
  78. bool IsKeyPressedAndTriggered(EKey inKey, bool &ioPrevState) const
  79. {
  80. bool prev_state = ioPrevState;
  81. ioPrevState = IsKeyPressed(inKey);
  82. return ioPrevState && !prev_state;
  83. }
  84. /// Buffered keyboard input, returns EKey::Invalid for none
  85. virtual EKey GetFirstKey() = 0;
  86. virtual EKey GetNextKey() = 0;
  87. };