24.2 C
New York
Tuesday, April 22, 2025

c++ – Scuffling with MS GameInput


I come again to this little program periodically but it surely’s by no means labored.

#embrace 

#embrace 

IGameInput* gameInput = NULL;
IGameInputDevice* gameKeyboard = NULL;
IGameInputDevice* gameMouse = NULL;

IGameInputReading* keyReading = NULL;
IGameInputReading* mouseReading = NULL;

int predominant()
{
    GameInputCreate(&gameInput);


    gameInput->GetCurrentReading(GameInputKindKeyboard, gameKeyboard, &keyReading);
    gameInput->GetCurrentReading(GameInputKindMouse, gameMouse, &mouseReading);

    if (keyReading)
        keyReading->GetDevice(&gameKeyboard);  
    if (mouseReading)
        mouseReading->GetDevice(&gameMouse);

    whereas (true)
    {
        keyReading = NULL;
        mouseReading = NULL;
  
        // keyboard
        gameInput->GetCurrentReading(GameInputKindKeyboard, gameKeyboard, &keyReading);
        if (keyReading)
        {
            GameInputKeyState* keyState = NULL;

            int depend = keyReading->GetKeyCount();
                        
            if (SUCCEEDED(keyReading->GetKeyState(depend, keyState)))
                for (int ok = 0; ok < depend; ok++)
                {
                    if (keyState[k].virtualKey == 0x57)
                    {
          //              MessageBoxA(NULL, "Key Pressed", "w Key pressed", MB_OK);
                        std::cout << "w key pressed" << 'n';
                    }
                }
        }

        // mouse
        gameInput->GetCurrentReading(GameInputKindMouse, gameMouse, &mouseReading);

        if (mouseReading)
        {
            GameInputMouseState mouseState;

            if (SUCCEEDED(mouseReading->GetMouseState(&mouseState)))
            {
                if (mouseState.buttons & GameInputMouseButtons::GameInputMouseLeftButton)
                {
                    std::cout << "Left Click on Detected!" << std::endl;
                }
                if (mouseState.buttons & GameInputMouseButtons::GameInputMouseRightButton)
                {
                    std::cout << "Proper Click on Detected!" << std::endl;
                }
            }

        }

        if (keyReading)
           keyReading->Launch();

        if (mouseReading)
            mouseReading->Launch();
    }

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

    return 0;
}

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles