home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 339_01 / cldemo.c < prev    next >
Text File  |  1990-12-14  |  47KB  |  1,517 lines

  1. /* CLDEMO.C - Demo program for  THE CTRL+C LIBRARY functions */
  2.  
  3. /*
  4. ** CTRLCLIB - The CTRL+C Library(Tm)
  5. ** Copyright 1990 Trendtech Corporation, Inc.
  6. ** All Rights Reserved Worldwide
  7. */
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <conio.h>
  12.  
  13. #ifdef __TURBOC__
  14. #define CLEAR_SCREEN     clrscr()
  15. #define _outtext(x)         printf("%s",(x))
  16. #define _settextposition(r,c)         gotoxy(c,r) /* yes, Microsoft has it backwards */
  17. #define _settextwindow(r1,c1,r2,c2)   window(r1,c1,r2,c2)
  18. #define getch            getche
  19. #define DoTimeDelay(x)   delay(x + 50);
  20. #else
  21. #include <graph.h>
  22. #define CLEAR_SCREEN     _clearscreen(_GCLEARSCREEN)
  23. #endif
  24.  
  25. #include <dos.h>
  26. #include <bios.h>
  27. #include <time.h>
  28. #include <string.h>
  29.  
  30. #include "ctrlc.h"   /*  <-- this header must be in every source module */
  31.                      /*      calling a CTRLCLIB function. */
  32.  
  33. /* some neat boolean logic conditions */        
  34. #define FALSE   0
  35. #define TRUE    ~FALSE
  36. #define NO      FALSE
  37. #define YES     ~NO
  38. #define OFF     FALSE
  39. #define ON      ~OFF
  40.  
  41.  
  42. #define HELL_IS_BURNING 1
  43. #define QUIT  (((char)c=='q')||((scn==0x10)&&((char)c=='Q')))
  44.  
  45.  
  46. char *cr[]={"CTRLCLIB - The Ctrl+C Library(Tm)",
  47.             "Copyright 1990 Trendtech Corporation, Inc.",
  48.             "All Rights Reserved Worldwide" };
  49.  
  50.  
  51. /*
  52. ===================================================================
  53. = Function Prototypes
  54. ===================================================================
  55. */
  56.  
  57. int TEST1(void);
  58. int TEST2(void);
  59. int TEST3(void);
  60. int TEST4(void);
  61. int TEST5(void);
  62. int TEST6(void);
  63. int TEST7(void);
  64. int TEST8(void);
  65. int TEST9(void);
  66. int TEST10(void);
  67. int TEST11(void);
  68. int TEST12(void);
  69. int TEST13(void);
  70. int TEST14(void);
  71. int TEST15(void);
  72. int TEST16(void);
  73. int TEST17(void);
  74. int TEST18(void);
  75. int TEST19(void);
  76. int TEST20(void);
  77. int TEST21(void);
  78.  
  79. /*
  80. ===================================================================
  81. = Function Prototypes
  82. ===================================================================
  83. */
  84.  
  85. static void header(char *);
  86. static void footer(void);
  87.  
  88. #ifndef __TURBOC__
  89. static unsigned DoTimeDelay(int);
  90. #endif
  91.  
  92. static unsigned int ReadChar( char * );
  93. static char *spc(void);
  94.  
  95. void IntroScreen(void);
  96. void FinalScreen(void);
  97.  
  98. /*
  99. ===================================================================
  100. = Variables
  101. ===================================================================
  102. */
  103.  
  104. #ifndef __TURBOC__
  105. struct dostime_t t, *pt;
  106. time_t tm;
  107. #endif
  108.  
  109. char s[80], *sp;
  110. unsigned int c, i, scn;
  111.  
  112. /*
  113. ===================================================================
  114. =           M A I N  
  115. ===================================================================
  116. */
  117.  
  118. void main(void)
  119.    {
  120.  
  121. #ifdef __TURBOC__
  122.    delay(0);
  123. #else
  124.    time(&tm);
  125.    srand((unsigned)tm);
  126. #endif
  127.  
  128.    IntroScreen();
  129.  
  130.    while(HELL_IS_BURNING)
  131.       {
  132.       if (TEST1()  == 'Q') break;
  133.       if (TEST2()  == 'Q') break;  
  134.       if (TEST3()  == 'Q') break;  
  135.       if (TEST4()  == 'Q') break;
  136.       if (TEST5()  == 'Q') break;
  137.       if (TEST6()  == 'Q') break;
  138.       if (TEST7()  == 'Q') break;
  139.       if (TEST8()  == 'Q') break;
  140.       if (TEST9()  == 'Q') break;
  141.       if (TEST10() == 'Q') break;
  142.       if (TEST11() == 'Q') break;
  143.       if (TEST12() == 'Q') break;
  144.       if (TEST13() == 'Q') break;
  145.       if (TEST14() == 'Q') break;
  146.       if (TEST15() == 'Q') break;
  147.       if (TEST16() == 'Q') break;
  148.       if (TEST17() == 'Q') break;
  149.       if (TEST18() == 'Q') break;
  150.       if (TEST19() == 'Q') break;
  151.       if (TEST20() == 'Q') break;
  152.       if (TEST21() == 'Q') break;
  153.       break;
  154.       }
  155.  
  156.    CLEAR_SCREEN;
  157.    FinalScreen();
  158.    exit(0);
  159.    }
  160.  
  161.  
  162. /*********************************************************************/
  163.  
  164. int TEST1(void)
  165.    {
  166.    static char far *txt[]={
  167. "This test illustrates COMPLETE trapping of the infamous ^C break.\n",
  168. "Using functions from CTRLCLIB, you can trap the <CTRL>+<C> and\n",
  169. "<CTRL>+<BREAK> keystrokes, as well as eliminate the ^C characters from\n",
  170. "echoing to STDOUT when either of these keys are pressed by the user.\n\n",
  171. "          PRESS  q  to quit this test, or  Q  to quit the demo...\n",
  172. ""};
  173.    
  174.    c = i = 0;
  175.    CLEAR_SCREEN;
  176.    header("TEST 1 - Demonstrate Full CTRL+C and CTRL+BREAK trapping\n\n");
  177.    do { printf("%s",txt[i]); } while (*txt[++i]);
  178.  
  179.    printf("\nPress any key, or try <CTRL>+<C> -or- <CTRL>+<BREAK>...\n\n");
  180.    
  181.    FullCtrlC(DISABLE);          /*  <<--*** CTRLCLIB Function *** */
  182.    
  183.    while(1)
  184.       {
  185.       if ( (i = QueryCtrlC()) != 0 ) /*  <<--*** CTRLCLIB Function *** */
  186.          {
  187.          switch (i)
  188.             {
  189.             case CTRLC: 
  190.                printf(" You pressed the <CTRL>+<C> keys\n");
  191.                break;
  192.             case CTRLBREAK:
  193.                printf(" You pressed the <CTRL>+<BREAK> keys\n");
  194.                break;
  195.             case CTRL2:
  196.                printf(" You pressed the <CTRL>+<2> keys\n");
  197.                break;
  198.             case ALT3:
  199.                printf(" You pressed the <ALT>+<kp-3> keys\n");
  200.                break;
  201.             default:
  202.                printf(" Whoops, this should never happen!!\n");
  203.                break;
  204.             }
  205.          printf("     Press any key...\n");
  206.          continue;
  207.          }
  208.          else
  209.             if ( !kbhit() ) continue;
  210.  
  211.       if ( (c = ReadChar(s)) == 0)       /*  read and print the char typed */
  212.          continue;                       /*  (not a printable char) */
  213.       printf(s);
  214.       if (QUIT) break;
  215.       }
  216.  
  217.    FullCtrlC(ENABLE);           /*  <<--*** CTRLCLIB Function *** */
  218.  
  219.    if (c != 'Q')
  220.       {
  221.       printf("\nCTRL+C and CTRL+BREAK have been ENABLED;  NOW press either set of keys to\n");
  222.       printf("'break' out of this demo program if you wish; -or- press any key to\n");
  223.       printf("continue the next test...");
  224.       getch();
  225.       }
  226.  
  227.    return(c);
  228.    }
  229.  
  230.  
  231. /*********************************************************************/
  232.  
  233. int TEST2(void)
  234.    {
  235.    static char far *txt[]={
  236. "This test illustrates how DOS normally echos a ^C to the screen when\n",
  237. "either <CTRL>+<C> or <CTRL>+<BREAK> is pressed.  Control-break is NOT\n",
  238. "trapped in this test, so it too acts like control-c.  \n\n",
  239. "       PRESS  q  to quit this test, or  Q  to quit demo...\n",
  240. ""};
  241.    
  242.    c = i = 0;
  243.    CLEAR_SCREEN;
  244.    header("TEST 2- Disable CTRL+C and illustrate ^C using DOS print functions");
  245.    do { printf("%s",txt[i]); } while (*txt[++i]);
  246.  
  247.    _settextposition(15,1);
  248.    printf("Now press any key, or try <CTRL>+<C> and <CTRL>+<BREAK>...\n\n");
  249.    
  250.  
  251.    CtrlC(DISABLE);              /*  <<--*** CTRLCLIB Function *** */
  252.  
  253.    while(1)
  254.       {
  255.       i = QueryCtrlC();         /*  <<--*** CTRLCLIB Function *** */
  256.       if (i == CTRLC)  /*  this is TRUE when either CTRL+C -or- CTRL+BREAK is hit */
  257.          {
  258.          printf(" You pressed the <CTRL>+<C> keys\n");
  259.          printf("     Press any key...\n");
  260.          continue;
  261.          }
  262.        else if (i == CTRLBREAK) /*  this will NEVER be true (in this demo section) */
  263.            {
  264.            printf(" You pressed the <CTRL>+<BREAK> keys\n");
  265.            printf("     Press any key...\n");
  266.            continue;
  267.            }
  268.          else
  269.              if ( ! kbhit()) continue;
  270.  
  271.       if ( (c = ReadChar(s)) == 0)           /*  read and print the char typed */
  272.          continue;                         /*  (not a printable char) */
  273.       printf(s);
  274.       if (QUIT) break;
  275.       }
  276.  
  277.    CtrlC(ENABLE);               /*  <<--*** CTRLCLIB Function *** */
  278.  
  279.    if (c != 'Q')
  280.       {
  281.       printf("\n\n\n\nCTRL+C has been ENABLED; press any key ");
  282.       printf("to continue to the next test...\n\n");
  283.       getch();
  284.       }
  285.  
  286.    return(c);
  287.    }
  288.  
  289.  
  290.  
  291. /*********************************************************************/
  292.  
  293. int TEST3(void)
  294.    {
  295.    static char far *txt[]={
  296. "This test shows how the installed interrupt handlers set a flag in the \n",
  297. "CTRLCLIB communication area to indicate which set of keys were pressed.\n",
  298. "In the case of pressing <CTRL>+<C>, we will still get the ^C characters \n",
  299. "echoed to the screen.  But in the case of pressing <CTRL>+<BREAK>, we will\n",
  300. "NOT get a ^C echoed.  The installed interrupt handlers are aware of the\n",
  301. "tests installed and will set the flag accordingly.  ALSO note that the ^C\n",
  302. "characters are printed on the screen by DOS when you use DOS functions.\n",
  303. "But for <CTRL>+<BREAK> traps, no ^C will be echoed to the screen because\n",
  304. "this test installs a control-break handler in addition to control-c.\n\n",
  305. "          PRESS  q  to quit this test, or  Q  to quit the demo...\n",
  306. ""};
  307.    
  308.    c = i = 0;
  309.    CLEAR_SCREEN;
  310.    header("TEST 3 - Example of disabling CTRL+BREAK *AND* CTRL+C (with ^C echo)\n\n");
  311.    do { printf("%s",txt[i]); } while (*txt[++i]);
  312.  
  313.    printf("\nNow press any key, or try <CTRL>+<C> -or- <CTRL>+<BREAK>...\n");
  314.    
  315.  
  316.    CtrlBreak(DISABLE);          /*  <<--*** CTRLCLIB Function *** */
  317.    CtrlC(DISABLE);              /*  <<--*** CTRLCLIB Function *** */
  318.  
  319.    while(1)
  320.       {
  321.       i = QueryCtrlC();         /*  <<--*** CTRLCLIB Function *** */
  322.       if (i == CTRLC) 
  323.          {
  324.          printf(" You pressed the <CTRL>+<C> keys\n");
  325.          printf("     Press any key...\n");
  326.          continue;
  327.          }
  328.        else if (i == CTRLBREAK)
  329.            {
  330.            printf(" You pressed the <CTRL>+<BREAK> keys\n");
  331.            printf("     Press any key...\n");
  332.            continue;
  333.            }
  334.          else
  335.              if ( ! kbhit()) continue;
  336.  
  337.       if ( (c = ReadChar(s)) == 0)           /*  read and print the char typed */
  338.          continue;                         /*  (not a printable char) */
  339.       printf(s);
  340.       if (QUIT) break;
  341.       }
  342.  
  343.    CtrlBreak(ENABLE);           /*  <<--*** CTRLCLIB Function *** */
  344.    CtrlC(ENABLE);               /*  <<--*** CTRLCLIB Function *** */
  345.  
  346.    if (c != 'Q')
  347.       {
  348.       printf("\n\n\nCTRL+C and CTRL+BREAK have been ENABLED again;  now\n");
  349.       printf(" press any key to continue with the next text...\n\n");
  350.       getch();
  351.       }
  352.  
  353.    return(c);
  354.    }
  355.  
  356.  
  357.  
  358. /*********************************************************************/
  359.  
  360. int TEST4(void)
  361.    {
  362.    static char far *txt[]={
  363. "Try to 'break' out of this program by first pressing and holding down\n",
  364. "the CONTROL key and then pressing the BREAK key.\n\n",
  365. "**NOTE: DO NOT PRESS <CTRL>+<C> for this test because the handler\n",
  366. "for this key combination has NOT been installed.  You'll leave\n",
  367. "the <CTRL>+<BREAK> handler still active in memory and you'll have to reboot!\n\n",
  368. "         PRESS  q  to quit this test, or  Q  to quit demo...\n",
  369. ""};
  370.  
  371.    c = i = 0;
  372.    header("TEST 4 - Example of disabling CONTROL+BREAK only");
  373.    do { _outtext(txt[i]); } while (*txt[++i]);
  374.    footer();
  375.  
  376.    _settextwindow(15,1, 24,80);
  377.    _outtext("Now press any key, or try <CTRL>+<BREAK>...\n\n");
  378.    
  379.  
  380.    CtrlBreak(DISABLE);          /*  <<--*** CTRLCLIB Function *** */
  381.  
  382.    while(1)
  383.       {
  384.       i = QueryCtrlC();         /*  <<--*** CTRLCLIB Function *** */
  385.       if (i == CTRLBREAK)
  386.          {
  387.          _outtext(" You pressed the <CTRL>+<BREAK> keys\n");
  388.          _outtext("     Press any key...\n");
  389.          continue;
  390.          }
  391.        else
  392.          if ( ! kbhit()) continue;
  393.  
  394.       if ( (c = ReadChar(s)) == 0)           /*  read and print the char typed */
  395.          continue;                         /*  (not a printable char) */
  396.       _outtext(s);
  397.       if (QUIT) break;
  398.       }
  399.  
  400.    CtrlBreak(ENABLE);           /*  <<--*** CTRLCLIB Function *** */
  401.  
  402.    if (c != 'Q')
  403.       {
  404.       _outtext("\n\n\n\nCTRL+BREAK has been ENABLED; press any key ");
  405.       _outtext("to continue to the next test...\n\n");
  406.       getch();
  407.       }
  408.       
  409.    return(c);
  410.    }
  411.  
  412. /*********************************************************************/
  413.  
  414. int TEST5(void)
  415.    {
  416.    static char far *txt[]={
  417. "This test illustrates the blocking of the system reset <CTRL>+<ALT>+<DEL> keys.\n\n",
  418. "**NOTE: DO NOT PRESS <CTRL>+<C> OR <CTRL>+<BREAK> here because those interrupt\n",
  419. "handlers have been ENABLED again from the prior tests.\n\n",
  420. "         PRESS  q  to quit this test, or  Q  to quit demo...\n",
  421. ""};
  422.  
  423.    c = i = 0;
  424.    header("TEST 5 - Example of disabling system reset - <CTRL>+<ALT>+<DEL>");
  425.    do { _outtext(txt[i]); } while (*txt[++i]);
  426.    footer();
  427.  
  428.    _settextwindow(15,1, 24,80);
  429.    _outtext("Now press any key, or try <CTRL>+<ALT>+<DEL>...\n\n");
  430.    
  431.    CtrlAltDel(DISABLE); /* <<--*** CTRLCLIB Function *** */
  432.  
  433.    while(1)
  434.       {
  435.       if (cl.BootFlag)  
  436.           {
  437.           _outtext("WHOOPS! You pressed the <CTRL>+<ALT>+<DEL> keys\n");
  438.           _outtext("Press any key...\n");
  439.           cl.BootFlag = 0;
  440.           continue;
  441.           }
  442.       if ( ! kbhit()) continue;
  443.  
  444.       if ( (c = ReadChar(s)) == 0)         /*  read and print the char typed */
  445.          continue;                         /*  (not a printable char) */
  446.       _outtext(s);
  447.       if (QUIT) break;
  448.       }
  449.  
  450.    CtrlAltDel(ENABLE); /* <<--*** CTRLCLIB Function *** */
  451.  
  452.    if (c != 'Q')
  453.       {
  454.       _outtext("\n\nCTRL+ALT+DEL has been ENABLED;  You can press <CTRL>+<ALT>+<DEL> to\n");
  455.       _outtext("REBOOT your system now; -or- just press any key to continue the next test..");
  456.       getch();
  457.       }
  458.       
  459.    return(c);
  460.    }
  461.  
  462.  
  463.  
  464. /*********************************************************************/
  465.  
  466. int TEST6(void)
  467.    {
  468.    static char far *txt[]={
  469. "This test illustrates the blocking of the system PAUSE keys.\n\n",
  470. "On systems equipped with the Enhanced keyboard, the key labeled\n",
  471. "PAUSE will pause the system.  On systems equipped with other keyboards\n",
  472. "the system pause keys are the <CTRL>+<NUMLOCK> keys.\n\n",
  473. "         PRESS  q  to quit this test, or  Q  to quit demo...\n",
  474. ""};
  475.  
  476.    c = i = 0;
  477.    header("TEST 6 - Example of disabling PAUSE  -or- <CTRL>+<NUMLOCK>");
  478.    do { _outtext(txt[i]); } while (*txt[++i]);
  479.    footer();
  480.  
  481.    _settextwindow(15,1, 24,80);
  482.  
  483.    _outtext("Now press any key to start, then try <PAUSE> or <CTRL>+<NUMLOCK>\n\n");
  484.    
  485.    CtrlcLibSetup( FCTRLC | PAUSEKEY ); /*  <<--*** CTRLCLIB Function *** */
  486.  
  487.    while(1)
  488.       {
  489.       if (cl.PauseFlag)
  490.           {
  491.           _outtext("WHOA! You tried to PAUSE the system!! \n");
  492.           _outtext("          Press any key...\n");
  493.           cl.PauseFlag = 0;
  494.           continue;
  495.           }
  496.                         /*  if accidently hit any <CTRL>+<BREAK> keys */
  497.       if ( QueryCtrlC() )       /*  <<--*** CTRLCLIB Function ** */
  498.            {
  499.            _outtext(" You're NOT supposed to press the BREAK keys; just the PAUSE key...\n");
  500.            _outtext("     Press any key...\n");
  501.            continue;
  502.            }
  503.       if ( ! kbhit()) continue;
  504.  
  505.       if ( (c = ReadChar(s)) == 0)         /*  read and print the char typed */
  506.          continue;                         /*  (not a printable char) */
  507.       _outtext(s);
  508.       if (QUIT) break;
  509.       }
  510.  
  511.    CtrlcLibCleanup();              /*  <<--*** CTRLCLIB Function *** */
  512.  
  513.    if (c != 'Q')
  514.       {
  515.       _outtext("\n\nPAUSE keys have been ENABLED; press any key to continue\n");
  516.       _outtext("with the next test...");
  517.       getch();
  518.       }
  519.       
  520.    return(c);
  521.    }
  522.  
  523.  
  524. /*********************************************************************/
  525.  
  526. int TEST7(void)
  527.    {
  528.    static char far *txt[]={
  529. "This test illustrates blocking of the DOS screen output pause <CTRL>+<S> keys.\n",
  530. "Pressing <CTRL>+<S> on all MS-DOS systems will pause screen output ONLY.  It\n",
  531. "will not pause the system as <PAUSE> or <CTRL>+<NUMLOCK> will do.\n\n",
  532. "         PRESS  q  to quit this test, or  Q  to quit demo...\n",
  533. ""};
  534.  
  535.    c = i = 0;
  536.    header("TEST 7 - Example of disabling the MS-DOS screen output pause <CTRL>+<S>");
  537.    do { _outtext(txt[i]); } while (*txt[++i]);
  538.    footer();
  539.  
  540.    _settextwindow(15,1, 24,80);
  541.  
  542.    _outtext("\nNow press any key to start, then try <CTRL>+<S>\n");
  543.    ReadChar(NULL);
  544.  
  545.    CtrlS(DISABLE);             /*  <<--*** CTRLCLIB Function *** */
  546.  
  547.    while(1)
  548.       {
  549.       DoTimeDelay(10);
  550.       sprintf(s,"%sWhile I'm scrolling, press any key, or try to pause with <CTRL>+<S>\n",spc());
  551.       _outtext(s);
  552.       if (cl.PauseFlag == CTRLS)
  553.           {
  554.           _outtext("\n\n      WHOA! You tried to PAUSE MS-DOS screen output!!\n");
  555.           DoTimeDelay(50);
  556.           _outtext("\n\n");
  557.           cl.PauseFlag = 0;
  558.           continue;
  559.           }
  560.       if ( ! kbhit()) continue;
  561.  
  562.       if ( (c = ReadChar(s)) == 0)         /*  read and print the char typed */
  563.          continue;                         /*  (not a printable char) */
  564.       _outtext(s);
  565.       if (QUIT) break;
  566.       }
  567.  
  568.    CtrlS(ENABLE);              /*  <<--*** CTRLCLIB Function *** */
  569.  
  570.    if (c != 'Q')
  571.       {
  572.       _outtext("\n\n<CTRL>+<S> keys have been ENABLED again; press any key to continue\n");
  573.       _outtext("with the next test...");
  574.       getch();
  575.       }
  576.       
  577.    return(c);
  578.    }
  579.  
  580.  
  581.  
  582.  
  583. /*********************************************************************/
  584.  
  585. int TEST8(void)
  586.    {
  587.    static char far *txt[]={
  588. "This test illustrates blocking of all pause keys; <CTRL>+<S> and <PAUSE>\n",
  589. " -or- <CTRL>+<NUMLOCK> keys\n\n",
  590. "          PRESS  q  to quit this test, or  Q  to quit demo...\n",
  591. ""};
  592.  
  593.    c = i = 0;
  594.    header("TEST 8 - Example of disabling ALL pause keys...");
  595.    do { _outtext(txt[i]); } while (*txt[++i]);
  596.    footer();
  597.  
  598.    _settextwindow(15,1, 24,80);
  599.  
  600.    _outtext("\nNow press any key to start, then try <CTRL>+<S> or <PAUSE>\n");
  601.    ReadChar(NULL);
  602.  
  603.    CtrlcLibSetup( CTRLBREAK | PAUSEKEY | CTRLS );/* <<--*** CTRLCLIB Function *** */
  604.  
  605.    while(1)
  606.       {
  607.       DoTimeDelay(10);
  608.       sprintf(s,"%sPress any key, or try <CTRL>+<S> -or- <PAUSE> -or- <CTRL>+<NUMLOCK>\n",spc());
  609.       _outtext(s);
  610.       if (cl.PauseFlag == PAUSEKEY)
  611.           {
  612.           _outtext("\n\n      WHOA! You tried to PAUSE the system with the PAUSE key!! \n");
  613.           DoTimeDelay(50);
  614.           _outtext("\n\n");
  615.           cl.PauseFlag = 0;
  616.           continue;
  617.           }
  618.          else if (cl.PauseFlag == CTRLS)
  619.             {
  620.             _outtext("\n\n      WHOA! You tried to PAUSE MS-DOS screen output!! \n");
  621.             DoTimeDelay(50);
  622.             _outtext("\n\n");
  623.             cl.PauseFlag = 0;
  624.             continue;
  625.             }
  626.       i = QueryCtrlC();       /* <<--*** CTRLCLIB Function *** */
  627.       if (i == CTRLBREAK)
  628.            {
  629.            _outtext("\n\n You're NOT supposed to press the <CTRL>+<BREAK> keys; just the pause keys...\n");
  630.            _outtext("     Press any key to continue...\n\n");
  631.            c = getch();
  632.            continue;
  633.            }
  634.          
  635.       if ( ! kbhit()) continue;
  636.  
  637.       if ( (c = ReadChar(s)) == 0)         /*  read and print the char typed */
  638.          continue;                         /*  (not a printable char) */
  639.       _outtext(s);
  640.       if (QUIT) break;
  641.       }
  642.  
  643.    CtrlcLibCleanup();              /*  <<--*** CTRLCLIB Function *** */
  644.  
  645.    if (c != 'Q')
  646.       {
  647.       _outtext("\n\nThe pause keys have been ENABLED again; press any key to continue\n");
  648.       _outtext("with the next test...");
  649.       getch();
  650.       }
  651.       
  652.    return(c);
  653.    }
  654.  
  655. /*********************************************************************/
  656.  
  657. int TEST9(void)
  658.    {
  659.    static char far *txt[]={
  660. "This test illustrates how to block the PRINT SCREEN function.  This happens\n"
  661. "when the user presses the key or keys that cause the entire screen to be \n",
  662. "echoed to the printer.  These keys are either the specific 'Print Scrn' key\n",
  663. "on the 101 Key Enhanced Keyboard, or the combination keys <SHIFT>+<PRTSCRN>\n",
  664. "keys on other keyboards.\n\n",
  665. "        PRESS  q  to quit this test, or  Q  to quit demo...\n",
  666. ""};
  667.  
  668.    c = i = 0;
  669.    header("TEST 9 - Example of disabling <PRTSCRN> screen printout");
  670.    do { _outtext(txt[i]); } while (*txt[++i]);
  671.    footer();
  672.  
  673.    _settextwindow(15,1, 24,80);
  674.    _outtext("Now press any key, or try <PRTSCRN>...\n\n");
  675.    
  676.  
  677.    PrintScreen(DISABLE);      /*  <<--*** CTRLCLIB Function *** */
  678.  
  679.    while(1)
  680.       {
  681.       if (cl.PrtScrFlag)
  682.          {
  683.          _outtext(" You pressed the <PRTSCRN> screen print keys\n");
  684.          _outtext("     Press any key...\n");
  685.          cl.PrtScrFlag = 0;
  686.          continue;
  687.          }
  688.        else
  689.          if ( ! kbhit()) continue;
  690.  
  691.       if ( (c = ReadChar(s)) == 0)         /*  read and print the char typed */
  692.          continue;                         /*  (not a printable char) */
  693.       _outtext(s);
  694.       if (QUIT) break;
  695.       }
  696.  
  697.    PrintScreen(ENABLE);       /*  <<--*** CTRLCLIB Function *** */
  698.  
  699.    if (c != 'Q')
  700.       {
  701.       _outtext("\n\nScreen print has been ENABLED again;  NOW press <PRTSCN> to\n");
  702.       _outtext("print this screen; or press any key for the next test...\n");
  703.       getch();
  704.       }
  705.       
  706.    return(c);
  707.    }
  708.  
  709.  
  710. /*********************************************************************/
  711.  
  712. int TEST10(void)
  713.    {
  714.    static char far *txt[]={
  715. "This test illustrates how to block the print echo function.  Under MS-DOS,\n",
  716. "pressing certain keys will cause each line appearing on the screen to be\n",
  717. "echoed  to the printer.  These keys are either the <CTRL>+<PRTSCRN> keys\n",
  718. "or the <CTRL>+<P> keys.\n\n",
  719. "       PRESS  q  to quit this test, or  Q  to quit demo...\n",
  720. ""};
  721.  
  722.    c = i = 0;
  723.    header("TEST 10 - Example of disabling <CTRL>+<PRTSCRN> and <CTRL>+<P> keys");
  724.    do { _outtext(txt[i]); } while (*txt[++i]);
  725.    footer();
  726.  
  727.    _settextwindow(15,1, 24,80);
  728.    _outtext("Now press any key, or try <CTRL>+<PRTSCRN> -or- <CTRL>+<P>...\n\n");
  729.    
  730.  
  731.    CtrlP(DISABLE);            /*  <<--*** CTRLCLIB Function *** */
  732.  
  733.    while(1)
  734.       {
  735.       if (cl.PrtScrFlag == CTRLPRTSCR)
  736.             {
  737.             _outtext(" You pressed the <CTRL>+<PRTSCRN> screen echo print keys\n");
  738.             _outtext("     Press any key...\n");
  739.             cl.PrtScrFlag = 0;
  740.             continue;
  741.             }
  742.          else if (cl.PrtScrFlag == CTRLP)
  743.                {
  744.                _outtext(" You pressed the <CTRL>+<P> screen echo print keys\n");
  745.                _outtext("     Press any key...\n");
  746.                cl.PrtScrFlag = 0;
  747.                continue;
  748.                }
  749.             else
  750.                if ( ! kbhit()) continue;
  751.  
  752.       if ( (c = ReadChar(s)) == 0)         /*  read and print the char typed */
  753.          continue;                         /*  (not a printable char) */
  754.       _outtext(s);
  755.       if (QUIT) break;
  756.       }
  757.  
  758.    CtrlP(ENABLE);             /*  <<--*** CTRLCLIB Function *** */
  759.  
  760.    if (c != 'Q')
  761.       {
  762.       _outtext("\nScreen echo has been ENABLED again;  press any key to continue\n");
  763.       _outtext("to the next test...");
  764.       getch();
  765.       }
  766.       
  767.    return(c);
  768.    }
  769.  
  770.  
  771.  
  772. /*********************************************************************/
  773.  
  774. int TEST11(void)
  775.    {
  776.    static char far *txt[]={
  777. "This test illustrates how to block ALL the print screen keys.  These are the\n"
  778. "keys that cause the entire screen to print - <PRTSCRN> -or- <SHIFT>+<PRTSCRN>,\n",
  779. "and also causes each line appearing on the screen to be echoed to the printer.\n",
  780. "The echo keys are either the <CTRL>+<PRTSCRN> keys, or the <CTRL>+<P> keys.\n\n",
  781. "          PRESS  q  to quit this test, or  Q  to quit demo...\n",
  782. ""};
  783.  
  784.    c = i = 0;
  785.    header("TEST 11 - Example of disabling ALL of the PRINT SCREEN keys.");
  786.    do { _outtext(txt[i]); } while (*txt[++i]);
  787.    footer();
  788.  
  789.    _settextwindow(15,1, 24,80);
  790.    _outtext("Now press any key, or try <PRTSCRN> -or- <CTRL>+<PRTSCRN> -or- <CTRL>+<P>...\n\n");
  791.  
  792.  
  793.    CtrlcLibSetup( CTRLBREAK | PRINTSCREEN | CTRLP );/*  <<--*** CTRLCLIB Function *** */
  794.  
  795.    while(1)
  796.       {
  797.       i = QueryPrtScr();      /*  <<--*** CTRLCLIB Function *** */
  798.       if (i == PRINTSCREEN)
  799.           {
  800.           _outtext("WHOOPS! You tried to PRINTSCREEN the screen \n");
  801.           _outtext("Press any key...\n");
  802.           continue;
  803.           }
  804.          else if (i == CTRLP)
  805.             {
  806.             _outtext("WHOA! You tried to ECHO to the printer with CTRL+P!!\n");
  807.             _outtext("Press any key...\n");
  808.             continue;
  809.             }
  810.             else if (i == CTRLPRTSCR)
  811.                {
  812.                _outtext("WHOA! You tried to ECHO to the printer with CTRL+PRTSCR!!\n");
  813.                _outtext("Press any key...\n");
  814.                continue;
  815.                }
  816.             else if ( (i = QueryCtrlC()) == CTRLBREAK)
  817.                   {
  818.                   _outtext(" You're NOT supposed to press the <CTRL>+<BREAK> keys; just the print keys...\n");
  819.                   _outtext("     Press any key to continue...\n");
  820.                   c = getch();
  821.                   continue;
  822.                   }
  823.                else
  824.                   if ( ! kbhit()) continue;
  825.          
  826.       if ( (c = ReadChar(s)) == 0)         /*  read and print the char typed */
  827.          continue;                         /*  (not a printable char) */
  828.       _outtext(s);
  829.       if (QUIT) break;
  830.       }
  831.  
  832.    CtrlcLibCleanup();              /*  <<--*** CTRLCLIB Function *** */
  833.  
  834.    if (c != 'Q')
  835.       {
  836.       _outtext("\n\nAll Screen print functions have been ENABLED again;\n");
  837.       _outtext("press any key to continue to the next test...");
  838.       getch();
  839.       }
  840.       
  841.    return(c);
  842.    }
  843.  
  844. /*********************************************************************/
  845.  
  846. int TEST12(void)
  847.    {
  848.  
  849.    static char far *txt[]={
  850. "This test illustrates how you can set the LOCK keys to an initial\n",
  851. "desired setting.  The user can subsequently change the setting by\n",
  852. "simply pressing the key.  This test sets the CAPS LOCK to ON and the\n",
  853. "NUM LOCK to ON.  Before you manually change the setting, press some alpha keys\n",
  854. "and some keypad numeric keys to verify the settings.  If your keyboard\n",
  855. "has mode lights, they should indicate an ON condition.\n",
  856. ""};
  857.  
  858.    c = 0;
  859.    header("TEST 12 - Example of Initializing LOCK keys");
  860.    do { _outtext(txt[i]); } while (*txt[++i]);
  861.    footer();
  862.  
  863.    _settextwindow(15,1, 24,80);
  864.    _outtext("Press keys to verify settings, then UNLOCK keys and verify again\n\n");
  865.  
  866.    CapsLock(L_ON);      /*  <<--*** CTRLCLIB Function *** */
  867.    NumLock(L_ON);       /*  <<--*** CTRLCLIB Function *** */
  868.  
  869.    while(1)
  870.       {
  871.       if ( ! kbhit()) continue;
  872.       if ( (c = ReadChar(s)) == 0)
  873.          continue;                
  874.       _outtext(s);
  875.       if (QUIT) break;
  876.       }
  877.  
  878.    CapsLock(L_OFF);      /*  <<--*** CTRLCLIB Function *** */
  879.    NumLock(L_OFF);       /*  <<--*** CTRLCLIB Function *** */
  880.  
  881.    _outtext("     Press any key to continue with the next test...");
  882.    return(getch());
  883.    }
  884.  
  885.  
  886. /*********************************************************************/
  887.  
  888. int TEST13(void)
  889.    {
  890.    static char far *txt[]={
  891. "Notice that as you type letters, they will appear CAPITALIZED.  This\n",
  892. "is because this function will cause the CAPS LOCK key to be in an\n",
  893. "ALWAYS ON state.  No amount of pressing of pounding will turn it off.\n\n",
  894. "Keep pressing the CAPS lock key repeatedly to try to turn it off!\n\n",
  895. "          PRESS  q  anytime to quit this test...\n",
  896. ""};
  897.  
  898.    c = i = 0;
  899.    header("TEST 13 - Keeping the CAPS Lock key *ALWAYS ON* ");
  900.    do { _outtext(txt[i]); } while (*txt[++i]);
  901.    footer();
  902.  
  903.    _settextwindow(15,1, 24,80);
  904.    _outtext("Now press any key, or try to reset the CAPS LOCK from ON to off...\n\n");
  905.    
  906.    CapsLock(L_ALWAYSON);      /*  <<--*** CTRLCLIB Function *** */
  907.  
  908.    while(1)
  909.       {
  910.       if ( ! kbhit()) continue;
  911.       if ( (c = ReadChar(s)) == 0)
  912.          continue;                
  913.       _outtext(s);
  914.       if (QUIT) break;
  915.       }
  916.  
  917.    CapsLock(L_OFF);           /*  <<--*** CTRLCLIB Function *** */
  918.  
  919.    _outtext("\n\nThe CAPS LOCK has now been turned OFF;\n");
  920.    _outtext("If you have a keyboard equipped with the mode lights,\n");
  921.    _outtext("notice that you can now TOGGLE the CAPS lock key on and off.\n");
  922.    _outtext("Press any key to continue to the next test...");
  923.    return(getch());
  924.    }
  925.  
  926. /*********************************************************************/
  927.  
  928. int TEST14(void)
  929.    {
  930.    static char far *txt[]={
  931. "This test will lock the NUM key to ALWAYS ON.  Notice that as you hit the\n",
  932. "keys on the number pad,  NUMBERS will be echoed back.  It is because\n",
  933. "this function will cause the NUM LOCK key to be in an ALWAYS ON state.\n\n",
  934. "Keep pressing the NUM lock key repeatedly to try to turn it off!\n\n",
  935. "       PRESS  q  to quit this test, or  Q  to quit demo...\n",
  936. ""};
  937.  
  938.    c = i = 0;
  939.    header("TEST 14 - Keeping the NUM Lock key *ALWAYS ON*");
  940.    do { _outtext(txt[i]); } while (*txt[++i]);
  941.    footer();
  942.  
  943.    _settextwindow(15,1, 24,80);
  944.    _outtext("Now press any key, or try to reset the NUM LOCK from ON to off...\n\n");
  945.    
  946.    NumLock(L_ALWAYSON);       /*  <<--*** CTRLCLIB Function *** */
  947.  
  948.    while(1)
  949.       {
  950.       if ( ! kbhit()) continue;
  951.       if ( (c = ReadChar(s)) == 0)
  952.          continue;                
  953.       _outtext(s);
  954.       if (QUIT) break;
  955.       }
  956.  
  957.    NumLock(L_OFF);            /*  <<--*** CTRLCLIB Function *** */
  958.  
  959.    _outtext("\n\nThe NUM LOCK key has now been turned OFF;\n");
  960.    _outtext("If you have a keyboard equipped with the mode lights,\n");
  961.    _outtext("notice that you can now TOGGLE the NUM lock key on and off.\n");
  962.    _outtext("Press any key to continue to the next test...");
  963.    return(getch());
  964.    }
  965.  
  966.  
  967. /*********************************************************************/
  968.  
  969. int TEST15(void)
  970.    {
  971.    static char far *txt[]={
  972. "        Try to reset the NUM LOCK from ON to off...!!!\n\n",
  973. "        Try to set the CAPS LOCK from off to ON...!!!\n\n",
  974. "If your keyboard is not equipped with mode lights, type a letter key or a\n",
  975. "keypad number key after each keypress of either the CAPS lock key or the\n",
  976. "NUM lock key.\n\n"
  977. "       PRESS  q  to quit this test, or  Q  to quit demo...\n",
  978. ""};
  979.  
  980.    c = i = 0;
  981.    header("TEST 15 - NUM Lock *ALWAYS ON* and CAPS LOCK *ALWAYS OFF* test");
  982.    do { _outtext(txt[i]); } while (*txt[++i]);
  983.    footer();
  984.  
  985.    _settextwindow(15,1, 24,80);
  986.    _outtext("Now press any key, or try to turn NUM LOCK OFF, and CAPS LOCK ON\n\n");
  987.    
  988.  
  989.    CapsLock(L_ALWAYSOFF);     /*  <<--*** CTRLCLIB Function *** */
  990.    NumLock(L_ALWAYSON);       /*  <<--*** CTRLCLIB Function *** */
  991.  
  992.    while(1)
  993.       {
  994.       
  995.       if ( ! kbhit()) continue;
  996.       if ( (c = ReadChar(s)) == 0)
  997.          continue;                
  998.       _outtext(s);
  999.       if (QUIT) break;
  1000.       }
  1001.  
  1002.    NumLock(L_OFF);            /*  <<--*** CTRLCLIB Function *** */
  1003.    CapsLock(L_OFF);           /*  <<--*** CTRLCLIB Function *** */
  1004.  
  1005.    _outtext("\nThe NUM LOCK key and CAPS LOCK key are now released;\n");
  1006.    _outtext("If you have a keyboard equipped with the mode lights,\n");
  1007.    _outtext("notice that you can now TOGGLE both the NUM lock key and\n");
  1008.    _outtext("CAPS LOCK key on and off.\n");
  1009.    _outtext("Press any key to continue to the next test...");
  1010.    return(getch());
  1011.    }
  1012.  
  1013. /*********************************************************************/
  1014.  
  1015. int TEST16(void)
  1016.    {
  1017.    static char far *txt[]={
  1018. "        Try to reset the CAPS LOCK from ON to off...!!!\n",
  1019. "        Try to reset the NUM LOCK from ON to off...!!!\n",
  1020. "        Try to reset the SCROLL LOCK from ON to off...!!!\n\n",
  1021. "If your keyboard is not equipped with mode lights, type a letter key or a\n",
  1022. "keypad number key after each keypress of either the CAPS lock key or the\n",
  1023. "NUM lock key.\n\n"
  1024. "       PRESS  q  to quit this test, or  Q  to quit demo...\n",
  1025. ""};
  1026.  
  1027.    c = i = 0;
  1028.    header("TEST 16 - CAPS Lock, NUM Lock, and SCROLL Lock keys *ALWAYS ON* test");
  1029.    do { _outtext(txt[i]); } while (*txt[++i]);
  1030.    footer();
  1031.  
  1032.    _settextwindow(15,1, 24,80);
  1033.    _outtext("Now press any key, or try to turn CAPS, NUM, and SCROLL Lock keys OFF!\n\n");
  1034.  
  1035.    CapsLock(L_ALWAYSON);      /*  <<--*** CTRLCLIB Function *** */
  1036.    NumLock(L_ALWAYSON);       /*  <<--*** CTRLCLIB Function *** */
  1037.    ScrollLock(L_ALWAYSON);    /*  <<--*** CTRLCLIB Function *** */
  1038.  
  1039.    while(1)
  1040.       {
  1041.       if ( ! kbhit()) continue;
  1042.       if ( (c = ReadChar(s)) == 0)
  1043.          continue;                
  1044.       _outtext(s);
  1045.       if (QUIT) break;
  1046.       }
  1047.  
  1048.    NumLock(L_OFF);            /*  <<--*** CTRLCLIB Function *** */
  1049.    CapsLock(L_OFF);           /*  <<--*** CTRLCLIB Function *** */
  1050.    ScrollLock(L_OFF);         /*  <<--*** CTRLCLIB Function *** */
  1051.  
  1052.    _outtext("\nThe CAPS Lock, NUM Lock and SCROLL LOCK keys are now released;\n");
  1053.    _outtext("If you have a keyboard equipped with the mode lights,\n");
  1054.    _outtext("notice that you can now TOGGLE them on and off\n");
  1055.    _outtext("Press any key to continue to the next test...");
  1056.    return(getch());
  1057.    }
  1058.  
  1059. /*********************************************************************/
  1060.  
  1061. int TEST17(void)
  1062.    {
  1063.    static char far *txt[]={
  1064. "This function is called in a delay loop to *toggle* the CAPS Lock key\n",
  1065. "on and off.  \n\n",
  1066. "You don't have to press any keys - just watch the mode light for the\n",
  1067. "CAPS Lock key.  If your keyboard doesn't have mode lights, just press \n",
  1068. "q  to quit this test.\n\n",
  1069. ""};
  1070.  
  1071.    c = i = 0;
  1072.    header("TEST 17 - Toggle the CAPS Lock key ON and OFF" );
  1073.    do { _outtext(txt[i]); } while (*txt[++i]);
  1074.    footer();
  1075.  
  1076.    _settextwindow(15,1, 24,80);
  1077.    _outtext("Press the letter  q  anytime to quit this test\n");
  1078.  
  1079.    CapsLock(L_OFF);           /*  <<--*** CTRLCLIB Function *** */
  1080.  
  1081.    i = 0;
  1082.    while(1)
  1083.       {
  1084.  
  1085.       CapsLock(L_ON);         /*  <<--*** CTRLCLIB Function *** */
  1086.       DoTimeDelay(20);
  1087.       if (kbhit()) c = getch();
  1088.       if (QUIT) break;
  1089.  
  1090.       CapsLock(L_OFF);        /*  <<--*** CTRLCLIB Function *** */
  1091.       DoTimeDelay(20);
  1092.       if (kbhit()) c = getch();
  1093.       if (QUIT) break;
  1094.  
  1095.       }
  1096.  
  1097.    CapsLock(L_OFF);           /*  <<--*** CTRLCLIB Function *** */
  1098.  
  1099.    _outtext("\nThe CAPS Lock key has been released;\n");
  1100.    _outtext("Press any key to continue to the next test...");
  1101.    return(getch());
  1102.    }
  1103.  
  1104.  
  1105. /*********************************************************************/
  1106.  
  1107. int TEST18(void)
  1108.    {
  1109.    static char far *txt[]={
  1110. "These functions are called in a delay loop to *toggle* the CAPS Lock,\n",
  1111. "NUM Lock, and SCROLL Lock keys simultaneously causing the mode lights\n",
  1112. "to blink on and off.  This is simply a cute test to illustrate the power\n",
  1113. "and control your program can have by using the CTRLCLIB library.\n\n",
  1114. "You don't have to press any keys - just watch the mode lights for these\n",
  1115. "keys.  If your keyboard doesn't have mode lights, you can press q to\n",
  1116. "quit this test.\n\n",
  1117. ""};
  1118.  
  1119.    c = i = 0;
  1120.    header("TEST 18 - Toggle the CAPS, NUM, SCROLL keys ON and OFF");
  1121.    do { _outtext(txt[i]); } while (*txt[++i]);
  1122.    footer();
  1123.  
  1124.    _settextwindow(15,1, 24,80);
  1125.    _outtext("    Press the letter  q  anytime to quit this test\n\n");
  1126.  
  1127.    CapsLock(L_OFF);           /*  <<--*** CTRLCLIB Function *** */
  1128.    NumLock(L_OFF);            /*  <<--*** CTRLCLIB Function *** */
  1129.    ScrollLock(L_OFF);         /*  <<--*** CTRLCLIB Function *** */
  1130.  
  1131.    while(1)
  1132.       {
  1133.  
  1134.       CapsLock(L_ON);         /*  <<--*** CTRLCLIB Function *** */
  1135.       NumLock(L_ON);          /*  <<--*** CTRLCLIB Function *** */
  1136.       ScrollLock(L_ON);       /*  <<--*** CTRLCLIB Function *** */
  1137.       DoTimeDelay(20);
  1138.       if (kbhit()) c = getch();
  1139.       if (QUIT) break;
  1140.  
  1141.       CapsLock(L_OFF);        /*  <<--*** CTRLCLIB Function *** */
  1142.       NumLock(L_OFF);         /*  <<--*** CTRLCLIB Function *** */
  1143.       ScrollLock(L_OFF);      /*  <<--*** CTRLCLIB Function *** */
  1144.       DoTimeDelay(20);
  1145.       if (kbhit()) c = getch();
  1146.       if (QUIT) break;
  1147.       }
  1148.  
  1149.    CapsLock(L_OFF);           /*  <<--*** CTRLCLIB Function *** */
  1150.    NumLock(L_OFF);            /*  <<--*** CTRLCLIB Function *** */
  1151.    ScrollLock(L_OFF);         /*  <<--*** CTRLCLIB Function *** */
  1152.  
  1153.    _outtext("\nAll LOCK keys have been released;\n");
  1154.    _outtext("Press any key to continue to the next test...");
  1155.    return(getch());
  1156.    }
  1157.  
  1158.  
  1159. /*********************************************************************/
  1160.  
  1161. int TEST19(void)
  1162.    {
  1163.    static char far *txt[]={
  1164. "This test illustrates capturing the SYSTEM REQUEST key.  This is the\n"
  1165. "key that doesn't appear to be used for anything useful. If your\n",
  1166. "application needs to capture the <ALT>+<SYSRQ> key, this function\n",
  1167. "will do it for you.\n\n",
  1168. "If your keyboard is not equipped with a SysRq key, press q.\n\n"
  1169. "         PRESS  q  to quit this test, or  Q  to quit demo...\n",
  1170. ""};
  1171.  
  1172.    c = i = 0;
  1173.    header("TEST 19 - Example of capturing <ALT>+<SYSRQ> keys");
  1174.    do { _outtext(txt[i]); } while (*txt[++i]);
  1175.    footer();
  1176.  
  1177.    _settextwindow(15,1, 24,80);
  1178.    _outtext("Now press any key, or try <ALT>+<SYSRQ>...\n\n");
  1179.    
  1180.    PrintScreen(DISABLE);      /*  <<--*** CTRLCLIB Function *** */
  1181.    SysReq(INSTALL);           /*  <<--*** CTRLCLIB Function *** */
  1182.  
  1183.    while(1)
  1184.       {
  1185.       i = QuerySysReq();      /*  <<--*** CTRLCLIB Function *** */
  1186.       if (i)
  1187.           {
  1188.           _outtext("   You pressed the <ALT>+<SysRq> keys! \n");
  1189.           _outtext("           Press any key...\n");
  1190.           continue;
  1191.           }
  1192.       if ( ! kbhit()) continue;
  1193.       if ( (c = ReadChar(s)) == 0)
  1194.          continue;                
  1195.       _outtext(s);
  1196.       if (QUIT) break;
  1197.       }
  1198.  
  1199.    SysReq(REMOVE);            /*  <<--*** CTRLCLIB Function *** */
  1200.    PrintScreen(ENABLE);       /*  <<--*** CTRLCLIB Function *** */
  1201.  
  1202.    if (c != 'Q')
  1203.       {
  1204.       _outtext("\nThe SYS REQ key handler has been removed; press any key to continue\n");
  1205.       _outtext("with the next test...");
  1206.       getch();
  1207.       }
  1208.       
  1209.    return(c);
  1210.    }
  1211.  
  1212. /*********************************************************************/
  1213.  
  1214. int TEST20(void)
  1215.    {
  1216.    static char far *txt[]={
  1217. "The center key on the keypad is difficult to detect using conventional\n",
  1218. "C programming functions.  Part of the CTRLCLIB keyboard handler's\n",
  1219. "responsibility is to detect the keypad 5 keypress and set a flag in the\n",
  1220. "control structure.  This keypress is detected by the handler regardless\n",
  1221. "of the NUMLOCK key setting.\n\n",
  1222. "        PRESS  q  to quit this test, or  Q  to quit demo...\n",
  1223. ""};
  1224.  
  1225.    c = i = 0;
  1226.    header("TEST 20 - Example of capturing the <KEYPAD 5> keypress");
  1227.    do { _outtext(txt[i]); } while (*txt[++i]);
  1228.    footer();
  1229.  
  1230.    _settextwindow(15,1, 24,80);
  1231.    _outtext("Now press any key, or try <KEYPAD 5>...\n\n");
  1232.    
  1233.    cl.KeyPad5Flag = 0;          /* make sure it's OFF */
  1234.    FullCtrlC(DISABLE);          /*  <<--*** CTRLCLIB Function *** */
  1235.  
  1236.    while(1)
  1237.       {
  1238.       if ( QueryKeyPad5() )  /*  <<--*** CTRLCLIB Function *** */
  1239.          {
  1240.          _outtext(" You pressed the <KEYPAD 5> key\n");
  1241.          _outtext("     Press any key...\n");
  1242.          continue;
  1243.          }
  1244.        else
  1245.          if ( ! kbhit()) continue;
  1246.  
  1247.       if ( (c = ReadChar(s)) == 0)         /*  read and print the char typed */
  1248.          continue;                         /*  (not a printable char) */
  1249.       _outtext(s);
  1250.       if (QUIT) break;
  1251.       }
  1252.  
  1253.    FullCtrlC(ENABLE);           /*  <<--*** CTRLCLIB Function *** */
  1254.  
  1255.    if (c != 'Q')
  1256.       {
  1257.       _outtext("Press any key for the next test...\n");
  1258.       getch();
  1259.       }
  1260.       
  1261.    return(c);
  1262.    }
  1263.  
  1264.  
  1265. /*********************************************************************/
  1266.  
  1267. int TEST21(void)
  1268.    {
  1269.    static char far *txt[]={
  1270. "This test illustrates the simplicity with which you can use CTRLCLIB\n",
  1271. "and the power that it gives your programs.  The single library function\n",
  1272. "call shown below will trap the keypress sequences that could cause your\n",
  1273. "program a lot of grief:\n",
  1274. "     CtrlcLibSetup( FCTRLC | CTRLALTDEL | PAUSEKEY | CTRLPRTSCR \\\n",
  1275. "                    PRINTSCREEN | SYSREQ | CTRLS | CTRLP );\n", 
  1276. "At the end of this test all of the above traps and interrupts will be cleared\n",
  1277. "with the following single function call issued just before program\n",
  1278. "termination:   CtrlcLibCleanup(void);\n",
  1279. ""};
  1280.  
  1281.    c = i = 0;
  1282.    header("TEST 21 - The CTRLCLIB Library Grand Finale - Trap 'em all...");
  1283.    do { _outtext(txt[i]); } while (*txt[++i]);
  1284.    footer();
  1285.  
  1286.    _settextwindow(15,1, 24,80);
  1287.    _outtext("Now press any key, or try these:\n");
  1288.  
  1289.    _outtext("     <CTRL>+<BREAK>,  <CTRL>+<C>\n");
  1290.    _outtext("     <CTRL>+<2>,      <ALT>+<keypad 3>\n");
  1291.    _outtext("     <CTRL>+<S>,      <ALT>+<SYSREQ>\n");
  1292.    _outtext("     <PRINTSCREEN> key\n");
  1293.    _outtext("     <CTRL>+<PRTSCREEN>,  <CTRL>+<P>\n");
  1294.    _outtext("     <PAUSE>  -or- <CTRL>+<NUMLOCK>\n");
  1295.    _outtext("     <CTRL>+<ALT>+<DEL>\n");
  1296.  
  1297.    _outtext("                       Type Q or q to quit demo...\n");
  1298.    
  1299.  
  1300.                               /* * CTRLCLIB Function ** */
  1301.    CtrlcLibSetup( FCTRLC|CTRLALTDEL|PAUSEKEY|CTRLPRTSCR );
  1302.    CtrlcLibSetup( PRINTSCREEN | SYSREQ | CTRLS | CTRLP ); 
  1303.  
  1304.    while(1)
  1305.       {
  1306.       if ( (i = QueryCtrlC()) != 0 )    /*  <<--*** CTRLCLIB Function *** */
  1307.          {
  1308.          switch (i)
  1309.             {
  1310.             case CTRLC: 
  1311.                _outtext("You pressed the <CTRL>+<C> keys\n");
  1312.                break;
  1313.             case CTRLBREAK:
  1314.                _outtext("You pressed the <CTRL>+<BREAK> keys\n");
  1315.                break;
  1316.             case CTRL2:
  1317.                _outtext("You pressed the <CTRL>+<2> keys\n");
  1318.                break;
  1319.             case ALT3:
  1320.                _outtext("You pressed the <ALT>+<kp-3> keys\n");
  1321.                break;
  1322.             default:
  1323.                _outtext(" Whoops, this should never happen!!\n");
  1324.                break;
  1325.             }
  1326.          _outtext("          Press any key...\n");
  1327.          continue;
  1328.          }
  1329.       if (cl.BootFlag)  
  1330.          {
  1331.          _outtext("WHOOPS! You pressed the <CTRL>+<ALT>+<DEL> keys\n");
  1332.          _outtext("          Press any key...\n");
  1333.          cl.BootFlag = 0;
  1334.          continue;
  1335.          }
  1336.       if (cl.PauseFlag == PAUSEKEY)
  1337.           {
  1338.           _outtext("You pressed the system <PAUSE> key\n");
  1339.           _outtext("          Press any key...\n");
  1340.           cl.PauseFlag = 0;
  1341.           continue;
  1342.           }
  1343.          else if (cl.PauseFlag == CTRLS)
  1344.             {
  1345.             _outtext("You pressed the <CTRL>+<S> to pause MS-DOS screen output\n");
  1346.             _outtext("          Press any key...\n");
  1347.             cl.PauseFlag = 0;
  1348.             continue;
  1349.             }
  1350.  
  1351.       i = QueryPrtScr();      /*  <<--*** CTRLCLIB Function *** */
  1352.       if (i == PRINTSCREEN)
  1353.           {
  1354.           _outtext("You pressed the <PRINTSCREEN> key(s)\n");
  1355.           _outtext("          Press any key...\n");
  1356.           continue;
  1357.           }
  1358.          else if (i == CTRLP)
  1359.             {
  1360.             _outtext("You pressed the <CTRL>+<P> screen echo keys\n");
  1361.             _outtext("          Press any key...\n");
  1362.             continue;
  1363.             }
  1364.             else if (i == CTRLPRTSCR)
  1365.                {
  1366.                _outtext("You pressed the <CTRL>+<PRTSCR> screen echo keys\n");
  1367.                _outtext("          Press any key...\n");
  1368.                continue;
  1369.                }
  1370.  
  1371.       if( QuerySysReq() )    /*  <<--*** CTRLCLIB Function *** */
  1372.          {
  1373.          _outtext("You pressed the <ALT>+<SysRq> keys! \n");
  1374.          _outtext("          Press any key...\n");
  1375.          continue;
  1376.          }
  1377.  
  1378.       if ( QueryKeyPad5() )  /*  <<--*** CTRLCLIB Function *** */
  1379.          {
  1380.          _outtext(" You pressed the <KEYPAD 5> key\n");
  1381.          _outtext("     Press any key...\n");
  1382.          continue;
  1383.          }
  1384.          
  1385.       if ( !kbhit() ) continue;
  1386.  
  1387.       if ( (c = ReadChar(s)) == 0)           /*  read and print the char typed */
  1388.          continue;                         /*  (not a printable char) */
  1389.       _outtext(s);
  1390.       if (QUIT) break;
  1391.       }
  1392.  
  1393.    CtrlcLibCleanup();              /*  <<--*** CTRLCLIB Function *** */
  1394.    return(c);
  1395.    }
  1396.  
  1397.  
  1398. /*********************************************************************/
  1399.  
  1400. static void header(char *st)
  1401.    {
  1402.    CLEAR_SCREEN;
  1403.    _settextwindow(1,1,14,80);
  1404.    _outtext("CTRLCLIB - The Ctrl+C Library(Tm)");
  1405.    _outtext("   -   Copyright 1990 - Trendtech Corporation\n");
  1406.    _settextposition(3,1);
  1407.    _outtext(st);
  1408.    _settextposition(5,1);
  1409.    return;
  1410.    }
  1411.  
  1412. /*********************************************************************/
  1413.  
  1414. static void footer(void)
  1415.    {
  1416.    static char st[]=
  1417. "==========================================================================";
  1418.    _settextposition(14,1);
  1419.    _outtext(st);
  1420. #ifdef __TURBOC__
  1421.    printf("\n");
  1422. #endif
  1423.    return;
  1424.    }
  1425.  
  1426. /*********************************************************************/
  1427.  
  1428. #ifndef __TURBOC__
  1429. static unsigned DoTimeDelay(int timedelay)
  1430.    {
  1431.    unsigned accumhun, oldhun;
  1432.  
  1433.    accumhun = 0;
  1434.    _dos_gettime(&t);
  1435.    pt = &t;
  1436.  
  1437.    while(HELL_IS_BURNING)
  1438.       {
  1439.       oldhun = pt->hsecond;
  1440.       _dos_gettime(&t);
  1441.       pt = &t;
  1442.       accumhun = accumhun + (((100 - oldhun) + pt->hsecond) % 100);
  1443.       if (accumhun >= (unsigned)timedelay)
  1444.          break;                 /* exit when time elapsed */
  1445.       }
  1446.  
  1447.    return(accumhun);
  1448.    }
  1449. #endif
  1450.  
  1451.  
  1452.  
  1453. /*********************************************************************/
  1454.  
  1455. static unsigned int ReadChar( char *sp)
  1456.    {
  1457.    static unsigned chr;
  1458.    int i;
  1459.  
  1460. #ifdef __TURBOC__
  1461.    chr = bioskey(0);
  1462. #else
  1463.    chr = _bios_keybrd(_KEYBRD_READ);
  1464. #endif
  1465.  
  1466.    if (sp == NULL) return(chr);
  1467.    scn = (chr >> 8);                    /*  get scan code */
  1468.    i =  (unsigned char)(chr & 0x00FF);  /*  strip scan code */
  1469.  
  1470.    switch (i)
  1471.       {
  1472.       case 0x20:
  1473.          sprintf(sp,"          You pressed the SPACEBAR\n");
  1474.          break;
  1475.       case 0x0a:
  1476.       case 0x0d:
  1477.          sprintf(sp,"          You pressed the <cr> key\n");
  1478.          break;
  1479.       case 0x1a:
  1480.          sprintf(sp,"          You pressed the <^Z> key\n");
  1481.          break;
  1482.       case 0x08:
  1483.          sprintf(sp,"          You pressed the <BKSP> key\n");
  1484.          break;
  1485.       case 0x09:
  1486.          sprintf(sp,"          You pressed the <TAB> key\n");
  1487.          break;
  1488.       case 0x13:
  1489.          sprintf(sp,"          You pressed the <^S> key\n");
  1490.          break;
  1491.       default:
  1492.          sprintf(sp,"          You pressed the %c key\n",i);
  1493.          break;
  1494.       }
  1495.  
  1496.    return((unsigned)i);
  1497.    }
  1498.  
  1499.  
  1500. /*********************************************************************/
  1501.  
  1502. static char *spc(void)
  1503.    {
  1504.     static char spaces[11]=
  1505.          {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\0'};
  1506.     static int i=0;
  1507.  
  1508.    if (++i > 10 ) i = 1;
  1509.    spaces[i-1] = ' ';
  1510.    spaces[i]   = '\0';
  1511.     return(&spaces[0]);
  1512.     }
  1513.  
  1514.  
  1515. /* --------------------------- End of Source ------------------------- */
  1516.  
  1517.