I need some help here. I try this for a while now but it won't work and I can't find anything online. I want to write my own input handling. At first I used XInput for gamepads and Win32 callbacks for Keyboard input. That worked so far. Then I stumbled across GameInput and it seemed to me like this is a more modern approach so I tried it. For Gamepads (at least the ones I got here to test) it works like a charm. Then I tried to get it to work for keayboard as well, but it just won't recognize any keystrokes.
I put together this minimum example after https://learn.microsoft.com/en-us/gaming/gdk/_content/gc/input/overviews/input-readings#a-simple-gamepad-input-loop
#include <GameInput.h>
#include <iostream>
#include <thread>
IGameInput* g_gameInput = nullptr;
IGameInputDevice* g_device = nullptr;
HRESULT InitializeInput()
{
return GameInputCreate(&g_gameInput);
}
void ShutdownInput()
{
if (g_device) g_device->Release();
if (g_gameInput) g_gameInput->Release();
}
bool PollGamepadInput()
{
IGameInputReading* reading;
if (SUCCEEDED(g_gameInput->GetCurrentReading(GameInputKindKeyboard, g_device, &reading)))
{
if (!g_device)
{
reading->GetDevice(&g_device);
auto info = g_device->GetDeviceInfo();
std::cout << "Family: " << info->deviceFamily << std::endl;
std::cout << "Capabilities: " << info->capabilities << std::endl;
std::cout << "Vendor: " << info->vendorId << std::endl;
std::cout << "Product: " << info->productId << std::endl;
if(info->displayName)
std::cout << "DisplayName: " << info->displayName->data << std::endl;
}
auto count = reading->GetKeyCount();
if (count > 0)
std::cout << "Keys: " << count << std::endl;
reading->Release();
return true;
}
if (g_device)
{
g_device->Release();
g_device = nullptr;
}
return true;
}
int main()
{
if (InitializeInput() != S_OK)
return -1;
while (PollGamepadInput())
std::this_thread::sleep_for(std::chrono::milliseconds(1));
ShutdownInput();
return 0;
}
but I get no key strokes. When I use GameInputKindGamepad as a filter type a can just use getGamepadState and it just works. Unfortunately there is no such thing as a getKeyboardState.
GameInput seems like a rather new thing, but the documentation states nothing about "Keyboards does not work yet". Does anyone have an idea on what I'm missing here?