Check for CTRL-C in a Console (Windows only)

Share your advanced PureBasic knowledge/code with the community.
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Check for CTRL-C in a Console (Windows only)

Post by Rings »

Code updated For 5.20+

Often it is usefull if the user press CTRL-C to abort a console-Programm.
This little Api-call do the trick form me, it installs a CallBack in the Console-Handler:

Code: Select all

OpenConsole()
ConsoleColor(14,0)
ConsoleLocate(10,12)
PrintN("PRESS CTRL-C to goto 'MyTest'")
SetConsoleCtrlHandler_(?MyTest,#true)

Repeat ;endless Loop
Delay(1)
ForEver

End

MyTest:
 Beep_(100,100)
 Beep_(200,100)
 CloseConsole()
 MessageRequester("Test","Hello, this is the end from CTRL-C",0)
End
SPAMINATOR NR.1