Control-Break in QB64

198 views Asked by At

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?

2

There are 2 answers

6
Azathoth On BEST ANSWER

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
2
Sir Jo Black On

I've written the code below (QB64) that intercept key-press and key-release.

On my Linux OS this programs runs, but it doesn't intercept the key-press nor the key-release of the break key.

I don't know if said behaviour is due to my OS, OS configuration or my keyboard (Logitech wireless). I think it's due to the QB64 function _KEYHIT behaviour.

PRINT "Hit Esc to exit"
DO
  _LIMIT 20
  x& = _KEYHIT

  IF x& <> x1& THEN
    IF x& < 0 THEN
      PRINT "-"; HEX$(-x&)
    ELSE
      PRINT "+"; HEX$(x&); " [";
      y& = x&
      WHILE y& > 256
        PRINT CHR$(y& MOD 256); "] [";
        y& = y& \ 256
      WEND
      PRINT CHR$(y&); "]"
    END IF
    x1& = x&
  END IF

  IF x = 27 THEN EXIT DO
LOOP
PRINT "Escape pressed."