Difficulty using Steamworks SDK to receiev screenshot request callback in my cpp app

29 views Asked by At

I'm experimenting with Steamworks SDK by creating a c++ console application that runs my steam game and integrates the steam SDK to receive callbacks.

This is my code:

 #include <iostream>
#include "../HeaderFiles/steam_api.h"
#include <thread>
#include <cstdlib> 

class MyGameClass {
public:
    MyGameClass() :
        m_ScreenshotReadyCallback(this, &MyGameClass::OnScreenshotReady),
        m_ScreenshotRequestedCallback(this, &MyGameClass::OnScreenshotRequested)
    {
        
        running = true;
    }

    ~MyGameClass() {
        running = false;
        if (gameThread.joinable()) {
            gameThread.join();
        }
    }

    void OnScreenshotRequested(ScreenshotRequested_t* pParam) {
        std::cerr << "Screenshot requested!" << std::endl;
        std::cout << "Screenshot hooked: " << pParam << std::endl;
    }

    void OnScreenshotReady(ScreenshotReady_t* pParam) {
        if (pParam->m_eResult == k_EResultOK) {
            std::cerr << "Screenshot ready!" << std::endl;

        }
        else {
        }
    }

    void StartGameExecutable() {
        gameThread = std::thread(&MyGameClass::RunGameExecutable, this);
    }

    void RunSteamCallbacks() {
        while (running) {

            SteamAPI_RunCallbacks();
            std::this_thread::sleep_for(std::chrono::milliseconds(16));
        }
    }

private:
    std::thread gameThread;
    bool running;

    void RunGameExecutable() {
        std::system("Game1.exe");
    }
    
    CCallback<MyGameClass, ScreenshotRequested_t> m_ScreenshotRequestedCallback;
    CCallback<MyGameClass, ScreenshotReady_t> m_ScreenshotReadyCallback;
};

int main() {
    if (!SteamAPI_Init()) {
        std::cerr << "SteamAPI initialization failed" << std::endl;
        return 1;
    }
    SteamScreenshots()->HookScreenshots(true);
    MyGameClass myGame;
    myGame.StartGameExecutable();

    bool  hooked = SteamScreenshots()->IsScreenshotsHooked();
    std::cout << "Screenshot hooked: " << hooked << std::endl;

    myGame.RunSteamCallbacks();

    SteamAPI_Shutdown();

    return 0;

}

My issue is that I do not receieve a ScreenshotRequested_t callback despite hooking screenshots with SteamScreenshots()->HookScreenshots(true);

Accoring to the docs:

By default Steam will handle taking screenshots, but you can take over control by hooking the screenshots using ISteamScreenshots::HookScreenshots. If you're hooking the screenshots you'll be getting a ScreenshotRequested_t callback when the user presses the screenshot hotkey. You can check if you're currently hooking screenshots with ISteamScreenshots::IsScreenshotsHooked.

When I take a screenshot, I receieve a ScreenshotReady_t callback but just not ScreenshotRequested_t. I need my application to manage taking screenshots and not Steam. Hopefully someone would know the cause of this issue.

This is a screenshot of the console after I take a screenshot:

enter image description here


0

There are 0 answers