Add Keyboard.IsAnyKeyDown
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -10,48 +10,20 @@
|
||||
API_CLASS(NoSpawn) class FLAXENGINE_API Keyboard : public InputDevice
|
||||
{
|
||||
DECLARE_SCRIPTING_TYPE_NO_SPAWN(Keyboard);
|
||||
public:
|
||||
protected:
|
||||
|
||||
/// <summary>
|
||||
/// The keyboard state.
|
||||
/// </summary>
|
||||
struct State
|
||||
{
|
||||
/// <summary>
|
||||
/// The input text length (characters count).
|
||||
/// </summary>
|
||||
uint16 InputTextLength;
|
||||
|
||||
/// <summary>
|
||||
/// The input text.
|
||||
/// </summary>
|
||||
Char InputText[32];
|
||||
|
||||
/// <summary>
|
||||
/// The keys.
|
||||
/// </summary>
|
||||
bool Keys[(int32)KeyboardKeys::MAX];
|
||||
|
||||
/// <summary>
|
||||
/// Clears the state.
|
||||
/// </summary>
|
||||
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<int32>(key)] && _prevState.Keys[static_cast<int32>(key)];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if any keyboard key is currently pressed.
|
||||
/// </summary>
|
||||
API_PROPERTY() bool IsAnyKeyDown() const;
|
||||
|
||||
public:
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user