Detect CTRL-C
BlitzMax Forums/BlitzMax Beginners Area/Detect CTRL-C
| ||
Is it possible to detect CTRL-C being pressed from a commandline app? |
| ||
You can add a signal handler for SIGINT, on unixy platforms, and something like a SetConsoleCtrlHandler() on Windows. |
| ||
How do i add a signal handler? |
| ||
Hiya, There are a couple of ways on Windows. I only know a Windows solution, maybe Brucey or someone else would help out with the other platforms? This is a simple example that uses SetConsoleCtrlHandler to handle the CTRL-C :- To test it you need to run the final generated exe. It won't work when the code is run from the IDE as the IDE thread picks up the CTRL-C and will terminate anyway. Use the close icon to close the console window. Hope it helps! |