KeyboardLinux.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. class ApplicationWindowLinux;
  8. /// Keyboard interface class which keeps track on the status of all keys and keeps track of the list of keys pressed.
  9. class KeyboardLinux : public Keyboard
  10. {
  11. public:
  12. /// Destructor
  13. virtual ~KeyboardLinux() override;
  14. /// Initialization / shutdown
  15. virtual bool Initialize(ApplicationWindow *inWindow) override;
  16. virtual void Shutdown() override;
  17. /// Update the keyboard state
  18. virtual void Poll() override;
  19. /// Checks if a key is pressed or not
  20. virtual bool IsKeyPressed(EKey inKey) const override { return mKeysPressed[(int)inKey]; }
  21. /// Buffered keyboard input, returns EKey::Invalid for none
  22. virtual EKey GetFirstKey() override;
  23. virtual EKey GetNextKey() override;
  24. private:
  25. void HandleEvent(const XEvent &inEvent);
  26. EKey ToKey(int inKey) const;
  27. ApplicationWindowLinux * mWindow = nullptr;
  28. bool mKeysPressed[(int)EKey::NumKeys] = { };
  29. StaticArray<EKey, 128> mPendingKeyBuffer;
  30. StaticArray<EKey, 128> mKeyBuffer;
  31. uint mCurrentKey = 0;
  32. };