C++ Stopping a while loop in the middle of a std::system command

Viewed 45

So I am making a fake hacking hub, and I have this piece of code within it:

void tree() {
    std::system("cls");
    while (not(GetKeyState(VK_BACK) & 0x8000)) {
        std::system("tree C:\\");
    }
}

With the while loop condition, I'm sure you can tell that I want it to stop when teh user presses the backspace key, but, when the std::system("tree C:\\") command is running, the program ignores any backspace presses until the tree command finishes, which, since there is no delay, is extremely difficult to tell when, and not even considering that you can't stop it at will. Anyway, so, any ideas how I would fix it?

1 Answers

You can't. As far as your program is concerned, a call to std::system is a single operation.

What you can do is reimplement what tree C:\ does, but also listen for backspaces to cancel that.

Related