How To Check for Ctrl-Break in Code

This code outlines how you monitor for a Ctrl-Break keystroke in a console program in PowerBasic Console Compiler.

Code
#include "WIN32API.INC"

'Flag to indicate that Ctrl-Break was pressed.
GLOBAL BreakFlag AS LONG

FUNCTION pbmain AS LONG

'Set up the handler
SetConsoleCtrlHandler codeptr(Handler_CtrlBreak), %TRUE

'The break-flag is true. Ctrl-Break was pressed.
IF BreakFlag THEN
   STDOUT "Ctrl-Break pressed." 
END IF

'Free the callback.
SetConsoleCtrlHandler codeptr(Handler_CtrlBreak), %FALSE

END FUNCTION


'This is the capture function. This is called when Ctrl-Break is pressed.
FUNCTION Handler_CtrlBreak() AS LONG
    BreakFlag = %TRUE
END FUNCTION



The Captian
Today they call you "crazy". Tomorrow they call you "ahead of your time."
Global Skywatch Learn about Chemtrails - You're breathing them now!
OnlyTheBestHerbs.com World-class supplements
Mercury Talk Why you are sick.
OneUp Domains Domains, Hosting, Email
1-800-358-4278 (U.S. & Canada)