diff --git a/Source/Engine/Input/Input.cpp b/Source/Engine/Input/Input.cpp
index d7796691b..44131504d 100644
--- a/Source/Engine/Input/Input.cpp
+++ b/Source/Engine/Input/Input.cpp
@@ -223,6 +223,27 @@ bool Mouse::Update(EventQueue& queue)
return false;
}
+void Keyboard::State::Clear()
+{
+ Platform::MemoryClear(this, sizeof(State));
+}
+
+Keyboard::Keyboard()
+ : InputDevice(SpawnParams(Guid::New(), TypeInitializer), TEXT("Keyboard"))
+{
+ _state.Clear();
+ _prevState.Clear();
+}
+
+bool Keyboard::IsAnyKeyDown() const
+{
+ // TODO: optimize with SIMD
+ bool result = false;
+ for (auto e : _state.Keys)
+ result |= e;
+ return result;
+}
+
void Keyboard::OnCharInput(Char c, Window* target)
{
// Skip control characters
diff --git a/Source/Engine/Input/Keyboard.h b/Source/Engine/Input/Keyboard.h
index f182f9731..7877b3f13 100644
--- a/Source/Engine/Input/Keyboard.h
+++ b/Source/Engine/Input/Keyboard.h
@@ -10,48 +10,20 @@
API_CLASS(NoSpawn) class FLAXENGINE_API Keyboard : public InputDevice
{
DECLARE_SCRIPTING_TYPE_NO_SPAWN(Keyboard);
-public:
+protected:
- ///
- /// The keyboard state.
- ///
struct State
{
- ///
- /// The input text length (characters count).
- ///
uint16 InputTextLength;
-
- ///
- /// The input text.
- ///
Char InputText[32];
-
- ///
- /// The keys.
- ///
bool Keys[(int32)KeyboardKeys::MAX];
-
- ///
- /// Clears the state.
- ///
- void Clear()
- {
- Platform::MemoryClear(this, sizeof(State));
- }
+ void Clear();
};
-protected:
-
State _state;
State _prevState;
- explicit Keyboard()
- : InputDevice(SpawnParams(Guid::New(), TypeInitializer), TEXT("Keyboard"))
- {
- _state.Clear();
- _prevState.Clear();
- }
+ explicit Keyboard();
public:
@@ -94,6 +66,11 @@ public:
return !_state.Keys[static_cast(key)] && _prevState.Keys[static_cast(key)];
}
+ ///
+ /// Checks if any keyboard key is currently pressed.
+ ///
+ API_PROPERTY() bool IsAnyKeyDown() const;
+
public:
///