hello everyone!
i'd like to know if theres a way to run my program until the user presses Esc button.
i use linux environment and my main function runs fork().i want the program to stop
the fork() when the user presses escape.
thank you!

You need some sort of event handling... Don't really know what libs are used under lin.

can you give me a hint?

As I said, I don't really now those libraries, try googling something like "c++ checking if key is pressed", or adding linux in there.

yes i have searched but c++ doesnt support an event handling so i'm curious if even theres a way to stop a loop when a key is pressed without using instructions like cin as they have to wait for an input.thank you anyway

there must be a library.
And what I mean is, you run a loop (at limited FPS, not to kill the CPU) and in every loop you check if the key was pressed.
Good tutorial on that is at LazyFoo, but it uses a graphic library (SDL) which IMO would be an overkill here, but why not?

In Standard C++ there is not. ESC is not a magic key today*. Just use ENTER.


* It never really was. The use of ESC has always been non-portable and much more difficult to program.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.