qb64

Control-Break in QB64


I have been using the following code to trap control-break but I get nothing in return:

Control-Break during program execution causes the following to happen:

1)Invokes interrupt trap 1Bh
2)Places 00:00 into keyboard buffer
3)Sets flag 80h at memory 40:71h

An example to detect Control-Break (compiled):

DO
   X$=INKEY$
   IF X$=CHR$(0)+CHR$(0) THEN
      PRINT "*break*"
      END
   END IF
LOOP

Another example to detect Control-Break (compiled):

DEF SEG = &H40
POKE &H71, 0
DEF SEG
DO
   DEF SEG = &H40
   X = PEEK(&H71)
   DEF SEG
   IF X = 128 THEN
      PRINT "*break*"
      END
   END IF
LOOP

Is there anything I am missing?


Solution

  • I have found the following code to trap ctrl-break in qb64:

    ON TIMER(1) GOSUB breaktrap
    TIMER ON
    x = _EXIT ' disable break
    DO
        _LIMIT 50
        x$ = INKEY$
    LOOP
    breaktrap:
    v = _EXIT
    IF v THEN
        PRINT "*break*"
        SLEEP 5
        SYSTEM
    END IF
    RETURN