0
\$\begingroup\$

I finally created an account. I've started coding MS GameInput, and have a problem retrieving keystrokes. I think I have a linking error but can't be sure I just started coding again after 15 years. The whole NUGET thing is new to me but in the package config it's there

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Microsoft.GameInput" version="0.2303.22621.3038" targetFramework="native" />
  <package id="NuJet" version="0.0.1" targetFramework="native" developmentDependency="true" />
</packages>'

I'm not crashing, the inputreading and the device are not NULL; but the count is zero and KeyState is NULL; In the debugger is says to load symbols for more information so I'm not doing something right. Here's some code called in the game loop:

 IGameInputReading* inputReading = NULL;
 GameInputKeyState* keyState = NULL;

  gameInput->GetCurrentReading(GameInputKindKeyboard, gameKeyboard, &inputReading);

  int count = inputReading->GetKeyCount();

  inputReading->GetKeyState(count, keyState);

  for (int k = 0; k < count; k++)
  {
      if (keyState[k].virtualKey == 0x57)
      {
          MessageBoxA(NULL, "Key Pressed", "w Key pressed", MB_OK);
      }
  }

forgive no error checking, it will come

Edit: I looked closer at the debug string and it's this:

gameInput   0x0000022fadb55c70 <Information not available, no symbols loaded for GameInputInbox.dll>    IGameInput *

now shouldn't that be gameinput.dll if so what can I do?

Here's a basic program I have:

#include <iostream>
#include <gameinput.h>

IGameInput* gameInput = NULL;
IGameInputDevice* gameKeyboard = NULL;
IGameInputReading* inputReading = NULL;


int main()
{
GameInputCreate(&gameInput);


// passing gameKeyboard as NULL device reads all devices connected, however we are filtering to the keyboard
gameInput->GetCurrentReading(GameInputKindKeyboard, gameKeyboard, &inputReading);

if (inputReading)
    inputReading->GetDevice(&gameKeyboard);  // since filterd the only device IS the keyboard

while (true)
{
    inputReading = NULL;
    GameInputKeyState* keyState = NULL;

    gameInput->GetCurrentReading(GameInputKindKeyboard, gameKeyboard, &inputReading);

    if (inputReading)
    {
        int count = inputReading->GetKeyCount();

        inputReading->GetKeyState(count, keyState);

        if (keyState)
            for (int k = 0; k < count; k++)
            {
                if (keyState[k].virtualKey == 0x57)
                {
                    MessageBoxA(NULL, "Key Pressed", "w Key pressed", MB_OK);
                }
            }
    }

    if (inputReading)
       inputReading->Release();
}

if (gameKeyboard) gameKeyboard->Release();
if (gameInput) gameInput->Release();

return 0;

}

I'm still wondering about the debug symbols not being loaded though.

\$\endgroup\$
3
  • \$\begingroup\$ I don't know if this is the issue you are running into but it is worth being aware of : IGameInput uses com light which runs asynchronously and takes a "moment" to come up. The interface will give various errors during that window. The temptation is to create the interface and then immediately query it resulting in these errors. As an experiment I did a spin loop on it to see how long it took to come up on my Ryzen 9 based system which got up to around 500,000 to 600,000 queries before it came back with a "SUCCESS". \$\endgroup\$ Commented Nov 7 at 11:31
  • \$\begingroup\$ so your saying is Im just not waiting long enough and should just let the while loop run for a while? I havent looked at this code for months but Ill come back to it and see sometime.. I know almost nothing of COM but am wondering aboutthe debug error not being gameinutdll \$\endgroup\$ Commented Nov 10 at 10:20
  • \$\begingroup\$ yes, letting it loop would work, calling "sleep" should also work (I haven't tried that). The final solution I used (after getting to work by just "hammering" the interface), is to create the IGameInput object very early in system startup, go off and do a lot of other work, then come back to it when it is time to start processing actual input. That works really well in a large system, but is hard to do in a test program. \$\endgroup\$ Commented Nov 10 at 12:34

2 Answers 2

0
\$\begingroup\$

other than not allocating 'keystate' to be of 'count' size, the biggest problem was Gameinput wont work in a console app unless the console owns a window with a message loop. Works just fine. Thanks all

\$\endgroup\$
1
  • \$\begingroup\$ Want to share the relevant bits of code you had to update, to save some time for the next person to struggle with this issue? Also, if this solved your problem, you should be able to click the ✅ icon to mark this answer as "Accepted". \$\endgroup\$ Commented Nov 17 at 12:06
0
\$\begingroup\$

as suggested heres the windows main function `int APIENTRY wWinMain(In HINSTANCE hInstance, In_opt HINSTANCE hPrevInstance, In LPWSTR lpCmdLine, In int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine);

// TODO: Place code here.

// Initialize global strings
LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadStringW(hInstance, IDC_GAMEINPUTWIN32, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);

// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
    return FALSE;
}

HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_GAMEINPUTWIN32));


// init game input
if (FAILED(GameInputCreate(&gameInput)) || !gameInput) {
    MessageBoxA(NULL, "init", "gameinput init failed", MB_OK);
    return -1;
}


MSG msg{}; 
// main message loop
while (msg.message != WM_QUIT)
{
    while (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    IGameInputReading* reading = nullptr;
    if (SUCCEEDED(gameInput->GetCurrentReading(GameInputKindKeyboard, nullptr, &reading)) && reading)
    {
        GameInputKeyState keyStates[64];
        UINT keyCount = reading->GetKeyCount();
        if (keyCount > 0 && keyCount < 64 && SUCCEEDED(reading->GetKeyState(keyCount, keyStates)))
        {
            for (UINT i = 0; i < keyCount; ++i)
            {
                if (keyStates[i].virtualKey == 'W')
                    MessageBoxA(NULL, "w key pressed", "Input Test", MB_OK); // std::cout << "W pressed\n";
            }
        }
       

        // mouse
        gameInput->GetCurrentReading(GameInputKindMouse, nullptr, &reading);

        if (reading)
        {
            GameInputMouseState* mouseState;
            mouseState = new GameInputMouseState;
            if (SUCCEEDED(reading->GetMouseState(mouseState)))
            {
                if (mouseState->buttons & GameInputMouseButtons::GameInputMouseLeftButton)
                {
                    MessageBoxA(NULL, "Left Click Detected!", "Input Test", MB_OK);
                }
                if (mouseState->buttons & GameInputMouseButtons::GameInputMouseRightButton)
                {
                    MessageBoxA(NULL, "Right Click Detected!", "Input Test", MB_OK);
                }
            }
            delete mouseState;
        }
        reading->Release();
    }

}

return (int) msg.wParam;

}

` im still new to formatting on this platform, sorry

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.