Çözüldü Klavye tuşları ile akış kontrolü nasıl sağlanır?

Bu konu çözüldü olarak işaretlenmiştir. Çözülmediğini düşünüyorsanız konuyu rapor edebilirsiniz.

KilicMert

Yoctopat
Katılım
2 Temmuz 2023
Mesajlar
2
Daha fazla  
Cinsiyet
Erkek
C++:
#include <iostream>
#include <cstdlib>
#include <conio.h>
#include <windows.h>

int main() {
    bool programRunning = false;
    bool programStopped = false;

    while (true) {
        if (GetAsyncKeyState(VK_F6) & 0x8000) {
            if (!programRunning) {
                programRunning = true;
                programStopped = false;
                std::cout << "Program started. Press F7 to stop." << std::endl;
            }
        }

        if (GetAsyncKeyState(VK_F7) & 0x8000) {
            if (programRunning && !programStopped) {
                programStopped = true;
                std::system("date 09/09/2024");
                std::cout << "Current date: 09/09/2024" << std::endl;
                std::cout << "Program stopped. Press F6 to start." << std::endl;
                while (GetAsyncKeyState(VK_F7) & 0x8000) {}
            }
        }

        if (programRunning && !programStopped) {
            int loopcount = 200;
            while (loopcount > 0) {
                std::system("date 1/01/2023");
                std::system("timeout 60");
                std::system("date 2/02/2023");
                std::system("timeout 60");
                std::system("date 3/03/2023");
                std::system("timeout 60");
                std::system("date 4/04/2023");
                std::system("timeout 60");
                std::system("date 5/05/2023");
                std::system("timeout 60");
                std::system("date 6/06/2023");
                std::system("timeout 60");
                std::system("date 7/07/2023");
                std::system("timeout 60");
                std::system("date 8/08/2023");
                std::system("timeout 60");
                std::system("date 9/09/2023");
                std::system("timeout 60");
                std::system("date 10/10/2023");
                std::system("timeout 60");
                std::system("date 11/11/2023");
                std::system("timeout 60");
                std::system("date 12/12/2023");
                std::system("timeout 60");
                std::system("date 1/01/2024");
                std::system("timeout 60");
                std::system("date 2/02/2024");
                std::system("timeout 60");
                std::system("date 3/03/2024");
                std::system("timeout 60");
                std::system("date 4/04/2024");
                std::system("timeout 60");
                std::system("date 5/05/2024");
                std::system("timeout 60");
                std::system("date 6/06/2024");
                std::system("timeout 60");
                std::system("date 7/07/2024");
                std::system("timeout 60");
                std::system("date 8/08/2024");

                std::cout << std::endl;
                std::cout << "Current date: 09/09/2024" << std::endl;

                loopcount -= 50;
            }
        }

        if (GetAsyncKeyState(VK_ESCAPE) & 0x8000) {
            break;
        }
    }

    std::cout << "Program exited." << std::endl;
    return 0;
}


Bu kodda F6 tuşuna bastığımda program başlamalı, F7 tuşuna bastığımda ise 09/09/2024 tarihine gelip durmalı ve tekrar F6 komutu beklemeli fakat bir türlü yapamadım, bana yardımcı olur musunuz?
 
Çözüm
İki seçenek var ya thread kullan ya da ikinci loop olmasın bütün işi tek bir loop içinde hallet.

Geri
Yukarı