KeyboardMacOS.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  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. /// Keyboard interface class which keeps track on the status of all keys and keeps track of the list of keys pressed.
  7. class KeyboardMacOS : public Keyboard
  8. {
  9. public:
  10. /// Initialization / shutdown
  11. virtual bool Initialize(ApplicationWindow *inWindow) override;
  12. virtual void Shutdown() override { }
  13. /// Update the keyboard state
  14. virtual void Poll() override;
  15. /// Checks if a key is pressed or not
  16. virtual bool IsKeyPressed(EKey inKey) const override { return mKeyPressed[(int)inKey]; }
  17. /// Buffered keyboard input, returns EKey::Invalid for none
  18. virtual EKey GetFirstKey() override;
  19. virtual EKey GetNextKey() override;
  20. /// Handle a key press event
  21. void OnKeyPressed(EKey inKey, bool inPressed);
  22. private:
  23. bool mKeyPressed[(int)EKey::NumKeys] = { };
  24. StaticArray<EKey, 128> mPendingKeyBuffer;
  25. StaticArray<EKey, 128> mKeyBuffer;
  26. uint mCurrentKey = 0;
  27. };