42 lines
1.2 KiB
C++
42 lines
1.2 KiB
C++
// 40250 CInputKeyboard with host key events in place of DirectInput polling (platform/EterLib/Input.cpp).
|
|
#include "EterLib/StdAfx.h"
|
|
#include "EterLib/Input.h"
|
|
|
|
#include <cstdio>
|
|
|
|
namespace {
|
|
struct Keyboard : CInputKeyboard
|
|
{
|
|
int downs = 0, ups = 0;
|
|
void OnKeyDown(int) override { ++downs; }
|
|
void OnKeyUp(int) override { ++ups; }
|
|
char Diks(int i) const { return ms_diks[i]; }
|
|
};
|
|
}
|
|
|
|
int main()
|
|
{
|
|
int failures = 0;
|
|
auto check = [&failures](bool ok, const char *name) {
|
|
if (!ok) {
|
|
std::fprintf(stderr, "FAIL %s\n", name);
|
|
++failures;
|
|
}
|
|
};
|
|
|
|
Keyboard kb;
|
|
check(kb.InitializeKeyboard(NULL), "InitializeKeyboard");
|
|
kb.KeyDown(DIK_LCONTROL);
|
|
check(kb.IsPressed(DIK_LCONTROL) && (kb.Diks(DIK_LCONTROL) & 0x80), "KeyDown records the key and the device byte");
|
|
kb.UpdateKeyboard();
|
|
check(kb.IsPressed(DIK_LCONTROL) && kb.downs == 0 && kb.ups == 0, "UpdateKeyboard neither polls nor dispatches");
|
|
kb.KeyUp(DIK_LCONTROL);
|
|
check(!kb.IsPressed(DIK_LCONTROL) && kb.Diks(DIK_LCONTROL) == 0, "KeyUp");
|
|
kb.KeyDown(-1);
|
|
kb.KeyDown(256);
|
|
kb.KeyDown(DIK_A);
|
|
Keyboard other; // the state is static: a new keyboard resets it, as in 40250
|
|
check(!kb.IsPressed(DIK_A), "constructor ResetKeyboard clears the shared state");
|
|
return failures ? 1 : 0;
|
|
}
|