Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!decwrl!lll-winken!xanth!xanth.cs.odu.edu!feit From: feit@cs.odu.edu (Mark A. Feit) Newsgroups: comp.os.msdos.programmer Subject: Re: Need help:Ctrl-C and Ctrl-Break Message-ID: Date: 31 Jul 90 18:19:45 GMT References: <1990Jul30.182430.7493@uokmax.uucp> <9627@tekigm2.MEN.TEK.COM> <1990Jul31.023745.1116@water.waterloo.edu> <5717@sbsvax.cs.uni-sb.de> Sender: news@cs.odu.edu Organization: Old Dominion University, Norfolk, VA Lines: 102 In-reply-to: fs-info@sbsvax.cs.uni-sb.de's message of 31 Jul 90 10:57:18 GMT In article <5717@sbsvax.cs.uni-sb.de> fs-info@sbsvax.cs.uni-sb.de (c/o Peter Gaal) writes: In article <1990Jul31.023745.1116@water.waterloo.edu>, nmouawad@water.waterloo.edu (Naji Mouawad) writes: > In article <9627@tekigm2.MEN.TEK.COM> dennisw@tekigm2.MEN.TEK.COM (Dennis G > Ward) writes: > > >input. What's the trick(s)? > >-- > >Dennis Ward dennisw@tekigm2.MEN.TEK.COM C1-820 (206)253-5428 > > The best method I know of, is to trap interrupt 09h. Write a little routine > that does the following: > ["little" deleted] Hmm, with your suggestion, you have to do scancode processing yourself, but why shouldn't MSDOS do the work for you ? [Pseudocode Obliterated... MS-DOS doesn't work for me. Ptui!] A quick solution in C that lets the runtime library do the dirty work: -------------8<-----Trim Here------------------ BOOL break_flag = FALSE; void ctrl_break( void ) { break_flag = TRUE; /* Do as little as possible in here... DOS gets in a strange state during interrupts and doesn't take kindly to I/O being done.*/ signal( SIGINT, ctrl_break ); } void ctrl_break_handler( void ) /* Or whatever you need... */ { signal( SIGINT, SIG_IGN ); /* Shut ^Break off completely... Don't want recursive calls. */ printf( "\n\nWHAM! Ctrl-Break!\n\n" ); break_flag = FALSE; /* Do your own thing in here */ signal( SIGINT, ctrl_break ); /* Reset things */ } main( int argc, char **argv ) { signal( SIGINT, ctrl_break ); for ( ; ; ) { /* forever */ /* Your code here */ if ( break_flag ) handle_ctrl_break(); } } -------------8<-----Trim Here------------------ A couple of suggestions: 1. Implement the code to check on break_flag inside of something that gets run very often. For example, I have a routine that gets called over and over while the system is waiting for a key. This also means that you can finish up critical operations and _then_ check for a break. 2. If you want to get rid of that nasty ^C on the screen, the only way I can find is to freopen() stdout to NUL. There's no other way as far as I can see without horking the keyboard interrupt (messy) or modifying your BIOS (out of the question). If you're using some screen I/O package, odds are it uses its own direct reads and writes and stdout just sits idle anyway. - Mark ................................... ................................... : Mark A. Feit : feit@cs.odu.edu : : Old Dominion University CS Dept. : feit@xanth.UUCP : : Norfolk, Virginia, U.S.A., Earth : "So where's my lunch, anyway?" : ................................... ................................... Y :)8 G-G-G-D-E-C -- - Mark ................................... ................................... : Mark A. Feit : feit@cs.odu.edu : : Old Dominion University CS Dept. : feit@xanth.UUCP : : Norfolk, Virginia, U.S.A., Earth : "So where's my lunch, anyway?" : ................................... ................................... Y :)8 G-G-G-D-E-C