MegaSteve/Input.ixx

35 lines
765 B
Plaintext
Raw Permalink Normal View History

module;
2022-08-05 23:50:08 +08:00
#include <memory>
export module Input;
export class KeyBoard
{
2022-08-05 23:50:08 +08:00
static bool LastKeyStatus[256];
static bool CurrKeyStatus[256];
public:
2022-08-05 23:50:08 +08:00
static void OnKeyMsg(char keycode, bool status)
{
2022-08-05 23:50:08 +08:00
CurrKeyStatus[keycode] = status;
}
static bool GetKey(char keycode)
{
2022-08-05 23:50:08 +08:00
return CurrKeyStatus[keycode];
}
static bool GetKeyUp(char keycode)
{
return LastKeyStatus[keycode] && !CurrKeyStatus[keycode];
}
static bool GetKeyDown(char keycode)
{
return !LastKeyStatus[keycode] && CurrKeyStatus[keycode];
}
static void Flush()
{
memcpy(LastKeyStatus, CurrKeyStatus, sizeof(CurrKeyStatus));
}
};
2022-08-05 23:50:08 +08:00
bool KeyBoard::LastKeyStatus[256]{};
bool KeyBoard::CurrKeyStatus[256]{};