2

I am using the following code in QB64 to trap Control-Break:

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

I would like to know if there is a way to trap Control-Alt-Delete in QB64.

eoredson
  • 1,167
  • 2
  • 14
  • 29
  • 2
    AFAIK, the answer is no, or at least you shouldn't without a very good reason. The key sequence generates a hardware interrupt that the OS handles. For example, Windows XP will start the Task Manager if I recall correctly, and Windows Vista and later will take you to a screen that allows you to log out, start the Task Manager, or lock the computer. If another program goes out of control, I'd like to be able to stop it, and I can't do that as easily while your program that traps Ctrl-Alt-Del is running. –  Oct 04 '16 at 00:39
  • This link describes why trapping Control-Alt-Break cannot be done without writing your own GINA dll: https://msdn.microsoft.com/en-us/library/aa375457(v=vs.85).aspx – eoredson Oct 04 '16 at 21:30

1 Answers1

1

This snip describes why Control-Alt-Delete is not trapped:

CONST KEY_RSHIFT& = 100303
CONST KEY_LSHIFT& = 100304
CONST KEY_RCTRL& = 100305
CONST KEY_LCTRL& = 100306
CONST KEY_RALT& = 100307
CONST KEY_LALT& = 100308
DO
    x = _KEYHIT
    IF x = CVI(CHR$(0) + CHR$(83)) THEN
        IF _KEYDOWN(KEY_RCTRL&) OR _KEYDOWN(KEY_LCTRL&) THEN
            IF _KEYDOWN(KEY_RALT&) OR _KEYDOWN(KEY_LALT&) THEN
                PRINT "KEYHIT: Ctrl-Alt-Delete"
            ELSE
                PRINT "KEYHIT: Ctrl-Delete"
            END IF
        ELSE
            IF _KEYDOWN(KEY_RALT&) OR _KEYDOWN(KEY_LALT&) THEN
                PRINT "KEYHIT: Alt-Delete"
            ELSE
                PRINT "KEYHIT: Delete"
            END IF
        END IF
    END IF
    k$ = INKEY$
LOOP UNTIL k$ = CHR$(27)
eoredson
  • 1,167
  • 2
  • 14
  • 29