port: EterLib/Input over host key events (DirectInput polling adapted)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-09-30 13:21:25 +09:00
co-authored by Claude Opus 5.5
parent 5d64311a4d
commit 32c5a09d6e
5 changed files with 206 additions and 42 deletions
+41
View File
@@ -0,0 +1,41 @@
// 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;
}