From 3a56b8a378884bef0cecb949d714dd8ba3c0a249 Mon Sep 17 00:00:00 2001 From: swiderskis <66870324+swiderskis@users.noreply.github.com> Date: Wed, 7 Feb 2024 13:25:56 +0000 Subject: [PATCH 1/2] Add keyboard class --- include/Keyboard.hpp | 65 ++++++++++++++++++++++++++++++++++++++++++++ include/Window.hpp | 7 +++++ 2 files changed, 72 insertions(+) create mode 100644 include/Keyboard.hpp diff --git a/include/Keyboard.hpp b/include/Keyboard.hpp new file mode 100644 index 00000000..c90c12fe --- /dev/null +++ b/include/Keyboard.hpp @@ -0,0 +1,65 @@ +#ifndef RAYLIB_CPP_INCLUDE_KEYBOARD_HPP_ +#define RAYLIB_CPP_INCLUDE_KEYBOARD_HPP_ + +#include "./raylib.hpp" + +namespace raylib { +/** + * Input-related functions: keyboard + */ +class Keyboard { + public: + /** + * Detect if a key has been pressed once + */ + static bool IsKeyPressed(int key) { + return ::IsKeyPressed(key); + } + + /** + * Detect if a key has been pressed again (Only PLATFORM_DESKTOP) + */ + static bool IsKeyPressedRepeat(int key) { + return ::IsKeyPressedRepeat(key); + } + + /** + * Detect if a key is being pressed + */ + static bool IsKeyDown(int key) { + return ::IsKeyDown(key); + } + + /** + * Detect if a key has been released once + */ + static bool IsKeyReleased(int key) { + return ::IsKeyReleased(key); + } + + /** + * Detect if a key is NOT being pressed + */ + static bool IsKeyUp(int key) { + return ::IsKeyUp(key); + } + + /** + * Get key pressed (keycode), call it multiple times for keys queued, returns 0 when the queue is empty + */ + static bool GetKeyPressed() { + return ::GetKeyPressed(); + } + + /** + * Get char pressed (unicode), call it multiple times for chars queued, returns 0 when the queue is empty + */ + static bool GetCharPressed() { + return ::GetCharPressed(); + } +}; +} // namespace raylib + +using RKeyboard = raylib::Keyboard; + +#endif // RAYLIB_CPP_INCLUDE_KEYBOARD_HPP_ \ No newline at end of file diff --git a/include/Window.hpp b/include/Window.hpp index dfa9d7c4..5baabe79 100644 --- a/include/Window.hpp +++ b/include/Window.hpp @@ -76,6 +76,13 @@ class Window { return ::WindowShouldClose(); } + /** + * Set a custom key to exit program (default is ESC) + */ + bool SetExitKey(int key) { + return ::SetExitKey(key); + } + /** * Close window and unload OpenGL context */ From 7ec44d19da4bb4f41391f87d86b22b1bbb37cb50 Mon Sep 17 00:00:00 2001 From: swiderskis <66870324+swiderskis@users.noreply.github.com> Date: Wed, 7 Feb 2024 13:28:30 +0000 Subject: [PATCH 2/2] Add missing newline at end of Keyboard.hpp file --- include/Keyboard.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/Keyboard.hpp b/include/Keyboard.hpp index c90c12fe..b111d2c5 100644 --- a/include/Keyboard.hpp +++ b/include/Keyboard.hpp @@ -62,4 +62,4 @@ class Keyboard { using RKeyboard = raylib::Keyboard; -#endif // RAYLIB_CPP_INCLUDE_KEYBOARD_HPP_ \ No newline at end of file +#endif // RAYLIB_CPP_INCLUDE_KEYBOARD_HPP_