BBS: Inland Empire Archive Date: 01-01-93 (20:16) Number: 234 From: AARON LAPIKAS Refer#: NONE To: JASON BAUMAN Recvd: NO Subj: CTRL-C Conf: (2) Quik_Bas
Hi again! > How can i have QuickBasic NOT abort a program whenever CTRL-C or CTRL- > BREAK is hit. I've tried making Password programs to put on friends > systems, but that always was the problem. Thanx a lot Well, the only way I know of to trap CTRL-BREAK is to compile NOT using the error checking option. To trap CTRL is easy. Try the following example: DO IF INKEY$ = CHR$(3) THEN PRINT "You pressed CTRL-C." END IF LOOP <a few seconds later> Now that I think about it, there is another way to trap the CTRL-BREAK key combination, here is how: DEF SEG = &H40 'Swich to BIOS segment POKE &H17, PEEK(&H17) AND (239) 'Shut off the Scroll-Lock key POKE &H17, PEEK(&H17) AND (223) 'Shut off the Num-Lock key POKE &H17, PEEK(&H17) AND (191) 'Shut off the Cap-Lock key DEF SEG 'Switch back to the default segment KEY 15, CHR$(&H0) + CHR$(&H1D) 'Define a key that traps CTRL KEY(15) ON 'Turn the key on. ON KEY(15) GOSUB Trap DO 'Idle loop used JUST for example LOOP Trap: RETURN This may be confusing, but I will explain now. The POKEs, PEEKs, and DEF SEGs at the beginning just turn off the Cap-Lock, Num-Lock, and Scroll-Lock keys if they were on. This must be done because trapping the CTRL key becomes easier. Then the program goes into the idle loop and waits. If the user presses CTRL, then the program branches to the subroutine TRAP. By doing this, it is impossible to press the key combination of CTRL-BREAK, and CTRL-anything also. If you try this and realize that you can't press CTRL-BREAK to exit to the QB environment, rather than rebooting, put the Cap-Lock and then press CTRL-BREAK - this will get you back to the environment. If you have any questions or problems, just ask. Aaron Now that I think about it, there may be another way to do this. --- FMail 0.90 * Origin: BCData Programming Inc - Sharon, PA (1:2601/506.1)
Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET