KeyboardLinux.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2024 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #pragma once
  5. #include <Input/Keyboard.h>
  6. #include <Jolt/Core/StaticArray.h>
  7. /// Keyboard interface class which keeps track on the status of all keys and keeps track of the list of keys pressed.
  8. class KeyboardLinux : public Keyboard
  9. {
  10. public:
  11. /// Destructor
  12. virtual ~KeyboardLinux() override;
  13. /// Initialization / shutdown
  14. virtual bool Initialize(Renderer *inRenderer) override;
  15. virtual void Shutdown() override;
  16. /// Update the keyboard state
  17. virtual void Poll() override;
  18. /// Checks if a key is pressed or not
  19. virtual bool IsKeyPressed(EKey inKey) const override { return mKeysPressed[(int)inKey]; }
  20. /// Buffered keyboard input, returns EKey::Invalid for none
  21. virtual EKey GetFirstKey() override;
  22. virtual EKey GetNextKey() override;
  23. private:
  24. void HandleEvent(const XEvent &inEvent);
  25. EKey ToKey(int inKey) const;
  26. Renderer * mRenderer = nullptr;
  27. bool mKeysPressed[(int)EKey::NumKeys] = { };
  28. StaticArray<EKey, 128> mPendingKeyBuffer;
  29. StaticArray<EKey, 128> mKeyBuffer;
  30. uint mCurrentKey = 0;
  31. };