mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-12-14 03:59:36 +00:00
Keyboard input
This commit is contained in:
63
GpCommon/GpBitfield.h
Normal file
63
GpCommon/GpBitfield.h
Normal file
@@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
template<unsigned int TSize>
|
||||
class GpBitfield
|
||||
{
|
||||
public:
|
||||
GpBitfield();
|
||||
GpBitfield(const GpBitfield<TSize> &other);
|
||||
|
||||
bool operator==(const GpBitfield<TSize> &other) const;
|
||||
bool operator!=(const GpBitfield<TSize> &other) const;
|
||||
|
||||
void Set(unsigned int index, bool v);
|
||||
bool Get(unsigned int index) const;
|
||||
|
||||
private:
|
||||
static const unsigned int TSizeBytes = (TSize + 7) / 8;
|
||||
uint8_t m_bytes[TSizeBytes];
|
||||
};
|
||||
|
||||
template<unsigned int TSize>
|
||||
inline GpBitfield<TSize>::GpBitfield()
|
||||
{
|
||||
for (unsigned int i = 0; i < TSizeBytes; i++)
|
||||
m_bytes[i] = 0;
|
||||
}
|
||||
|
||||
template<unsigned int TSize>
|
||||
inline GpBitfield<TSize>::GpBitfield(const GpBitfield<TSize> &other)
|
||||
: m_bytes(other.m_bytes)
|
||||
{
|
||||
}
|
||||
|
||||
template<unsigned int TSize>
|
||||
inline bool GpBitfield<TSize>::operator==(const GpBitfield<TSize> &other) const
|
||||
{
|
||||
for (unsigned int i = 0; i < TSizeBytes; i++)
|
||||
if (m_bytes[i] != other.m_bytes[i])
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template<unsigned int TSize>
|
||||
inline bool GpBitfield<TSize>::operator!=(const GpBitfield<TSize> &other) const
|
||||
{
|
||||
return !((*this) == other);
|
||||
}
|
||||
|
||||
template<unsigned int TSize>
|
||||
void GpBitfield<TSize>::Set(unsigned int index, bool v)
|
||||
{
|
||||
if (v)
|
||||
m_bytes[index / 8] |= (1 << (index & 7));
|
||||
else
|
||||
m_bytes[index / 8] &= ~(1 << (index & 7));
|
||||
}
|
||||
|
||||
template<unsigned int TSize>
|
||||
bool GpBitfield<TSize>::Get(unsigned int index) const
|
||||
{
|
||||
return (m_bytes[index / 8] & (1 << (index & 7))) != 0;
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace GpKeyModifiers
|
||||
{
|
||||
enum GpKeyModifier
|
||||
@@ -14,11 +16,12 @@ namespace GpKeyIDSubsets
|
||||
enum GpKeyIDSubset
|
||||
{
|
||||
kASCII,
|
||||
kUnicode,
|
||||
kSpecial,
|
||||
kNumPadASCII,
|
||||
kNumPadNumber,
|
||||
kNumPadSpecial,
|
||||
kFKey, // Key value is a raw F number
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
typedef GpKeyIDSubsets::GpKeyIDSubset GpKeyIDSubset_t;
|
||||
@@ -27,6 +30,7 @@ namespace GpKeySpecials
|
||||
{
|
||||
enum GpKeySpecial
|
||||
{
|
||||
kTab,
|
||||
kEscape,
|
||||
kPrintScreen,
|
||||
kScrollLock,
|
||||
@@ -47,11 +51,33 @@ namespace GpKeySpecials
|
||||
kLeftAlt,
|
||||
kRightAlt,
|
||||
kNumLock,
|
||||
kLeftArrow,
|
||||
kUpArrow,
|
||||
kDownArrow,
|
||||
kRightArrow,
|
||||
|
||||
kCount,
|
||||
};
|
||||
}
|
||||
|
||||
typedef GpKeySpecials::GpKeySpecial GpKeySpecial_t;
|
||||
|
||||
|
||||
namespace GpNumPadSpecials
|
||||
{
|
||||
enum GpNumPadSpecial
|
||||
{
|
||||
kSlash,
|
||||
kAsterisk,
|
||||
kMinus,
|
||||
kPlus,
|
||||
|
||||
kCount,
|
||||
};
|
||||
}
|
||||
|
||||
typedef GpNumPadSpecials::GpNumPadSpecial GpNumPadSpecial_t;
|
||||
|
||||
namespace GpKeyboardInputEventTypes
|
||||
{
|
||||
enum GpKeyboardInputEventType
|
||||
@@ -68,8 +94,12 @@ struct GpKeyboardInputEvent
|
||||
{
|
||||
union KeyUnion
|
||||
{
|
||||
GpKeySpecials::GpKeySpecial m_specialKey;
|
||||
GpKeySpecial_t m_specialKey;
|
||||
GpNumPadSpecial_t m_numPadSpecialKey;
|
||||
uint8_t m_numPadNumber;
|
||||
char m_asciiChar;
|
||||
uint32_t m_unicodeChar;
|
||||
unsigned char m_fKey;
|
||||
};
|
||||
|
||||
GpKeyboardInputEventType_t m_eventType;
|
||||
@@ -135,3 +165,5 @@ struct GpVOSEvent
|
||||
EventUnion m_event;
|
||||
GpVOSEventType_t m_eventType;
|
||||
};
|
||||
|
||||
static const unsigned int GpFKeyMaximumInclusive = 24;
|
||||
|
||||
Reference in New Issue
Block a user