tenho seguinte código c++

#include
#include
#include
#include
#include
#include
#include <cryptopp/keccak.h>
#include <cryptopp/hex.h>
#include <cryptopp/files.h>
#include <conio.h>
#include <windows.h>

namespace fs = std::filesystem;

// Function to calculate Keccak-512 hash of a file
std::string calculateKeccak512(const std::string& filePath) {
CryptoPP::Keccak_512 hash;
std::string digest;


CryptoPP::FileSource(filePath.c_str(), true,
    new CryptoPP::HashFilter(hash,
        new CryptoPP::HexEncoder(
            new CryptoPP::StringSink(digest), true)));

return digest;
}

// Function to set console text color
void setConsoleColor(int color) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color);
}

// Function to reset console text color
void resetConsoleColor() {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7); // Default color
}

// Function to clear console screen
void clearScreen() {
system("cls");
}

// Function to display the progress bar
void displayProgressBar(float progress) {
int barWidth = 50;
std::cout << "\r[";
int pos = static_cast(barWidth * progress);
for (int i = 0; i < barWidth; ++i) {
if (i < pos) std::cout << "=";
else if (i == pos) std::cout << ">";
else std::cout << " ";
}
std::cout << "] " << int(progress * 100.0) << "%";
std::cout.flush();
}

int main() {
// Step 1: Ask for the directory path
std::string directoryPath;
std::cout << "Digite o caminho da pasta que deve ser verificada: ";
std::getline(std::cin, directoryPath);


// Check if the directory exists
if (!fs::exists(directoryPath) || !fs::is_directory(directoryPath)) {
    std::cerr << "Diretório inválido!" << std::endl;
    return 1;
}

// Step 2: Collect files with specified extensions
std::vector<std::string> extensions = { ".exe", ".dll", ".asi" };
std::vector<std::pair<std::string, bool>> files; // Pair of filename and selection status

for (const auto& entry : fs::directory_iterator(directoryPath)) {
    if (entry.is_regular_file()) {
        std::string extension = entry.path().extension().string();
        if (std::find(extensions.begin(), extensions.end(), extension) != extensions.end()) {
            files.push_back({ entry.path().filename().string(), true }); // Default to selected (true)
        }
    }
}

// Step 3: Display files and allow selection/deselection
int currentIndex = 0;
int key;

while (true) {
    clearScreen();
    std::cout << "Use as setas para cima/baixo para navegar e ESPAÇO para selecionar/deselecionar arquivos." << std::endl;
    std::cout << "Arquivos:" << std::endl << std::endl;

    // Display all files, and highlight the current selection
    for (size_t i = 0; i < files.size(); ++i) {
        if (i == currentIndex) {
            setConsoleColor(112); // Highlight current selection
            std::cout << "> ";
        }
        else {
            std::cout << "  ";
        }

        if (files[i].second) {
            setConsoleColor(10); // Green text for selected files
        }
        else {
            setConsoleColor(12); // Red text for deselected files
        }

        std::cout << files[i].first;
        resetConsoleColor();
        std::cout << std::endl;
    }

    std::cout << std::endl;
    std::cout << "Pressione ENTER para gerar o arquivo." << std::endl;

    key = _getch();
    if (key == '\r') { // ENTER key
        break;
    }
    else if (key == 0 || key == 224) { // Arrow keys on Windows
        key = _getch();
        if (key == 72) { // Up arrow
            if (currentIndex > 0) currentIndex--;
        }
        else if (key == 80) { // Down arrow
            if (currentIndex < files.size() - 1) currentIndex++;
        }
    }
    else if (key == ' ') {
        // Toggle selection
        files[currentIndex].second = !files[currentIndex].second;
    }
}

// Step 4: Compute hashes and display progress bar
std::cout << "\nCalculando hashes..." << std::endl;
size_t totalFiles = std::count_if(files.begin(), files.end(), [](auto& f) { return f.second; });
size_t processedFiles = 0;

std::ofstream outputFile("rTales.ini");
if (!outputFile.is_open()) {
    std::cerr << "Erro ao abrir o arquivo de saída!" << std::endl;
    return 1;
}

for (auto& file : files) {
    if (file.second) { // If the file is selected
        std::string filePath = (fs::path(directoryPath) / file.first).string();
        std::string hash = calculateKeccak512(filePath);
        outputFile << "\"" << file.first << "\" : " << hash << std::endl;

        processedFiles++;
        float progress = (float)processedFiles / totalFiles;
        displayProgressBar(progress);
    }
}
std::cout << std::endl;

outputFile.close();
std::cout << "Hashes calculados e salvos em rTales.ini" << std::endl;
return 0;
}

Quando os arquivos são listados, o foco não está acompanhando o arquivo selecionado, o foco da está no fim do console, em vez de focar a visão do console no arquivo selecionado