2022-07-26 12:40:54 +08:00
|
|
|
module;
|
2022-08-05 23:50:08 +08:00
|
|
|
#include <memory>
|
2022-07-26 12:40:54 +08:00
|
|
|
|
|
|
|
export module Input;
|
|
|
|
|
|
|
|
export class KeyBoard
|
|
|
|
{
|
2022-08-05 23:50:08 +08:00
|
|
|
static bool LastKeyStatus[256];
|
|
|
|
static bool CurrKeyStatus[256];
|
2022-07-26 12:40:54 +08:00
|
|
|
|
|
|
|
public:
|
2022-08-05 23:50:08 +08:00
|
|
|
static void OnKeyMsg(char keycode, bool status)
|
2022-07-26 12:40:54 +08:00
|
|
|
{
|
2022-08-05 23:50:08 +08:00
|
|
|
CurrKeyStatus[keycode] = status;
|
2022-07-26 12:40:54 +08:00
|
|
|
}
|
|
|
|
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-07-26 12:40:54 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-08-05 23:50:08 +08:00
|
|
|
bool KeyBoard::LastKeyStatus[256]{};
|
|
|
|
bool KeyBoard::CurrKeyStatus[256]{};
|