home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / flash-c1.zip / CH3_1.DOC < prev    next >
Text File  |  1990-02-11  |  12KB  |  484 lines

  1. ..pgno01
  2. ..foot63A3-##
  3. ..head02L──────────────────────────────────────────────────────────────────────
  4. ..head04L──────────────────────────────────────────────────────────────────────
  5. ..head03ABiosKbdClr
  6. ■ Description
  7.  
  8.   Clear the keyboard buffer.
  9.  
  10.  
  11. ■ Summary
  12.  
  13.   Procedure BiosKbdClr;
  14.  
  15.  
  16. ■ Remarks
  17.  
  18.   BiosKbdClr uses the BIOS to clear any characters in the keyboard
  19.   buffer waiting to be read.
  20.  
  21.  
  22. ■ See Also
  23.  
  24.   DosKbdClr
  25.  
  26.  
  27. ■ Example
  28.  
  29.   #include <fpclib.h>
  30.  
  31.   main()
  32.   {
  33.      int Ch;
  34.  
  35.      BiosKbdClr();
  36.      Ch = GetKey();
  37.  
  38.   }
  39.  
  40.   In this example the keyboard buffer is flushed before reading a
  41.   keystroke from the keyboard.
  42. ..page
  43. ..head03ABiosKbdGetElmt
  44. ■ Description
  45.  
  46.   Returns an integer value for the key pressed on the keyboard.
  47.  
  48.  
  49. ■ Summary
  50.  
  51.   Function BiosKbdGetElmt : Integer;
  52.  
  53.  
  54. ■ Remarks
  55.  
  56.   BiosKbdGetElmt will return an integer in the range of 0-388.  Use
  57.   Appendix C as a guide to find the keyboard element code this
  58.   function returns for a particular key pressed on the keyboard.
  59.   When using DOS function calls there is not any method available to
  60.   distinguish the difference between some keystokes and key
  61.   combinations.  An example of this is the Enter key and the Ctrl-M
  62.   keys, both return a value of 145. Key combinations using the control
  63.   key with an alpha character and all other ascii characters will be
  64.   offset by 132.
  65.  
  66.  
  67. ■ See Also
  68.  
  69.   BiosKbdRead, DosKbdGetElmt, DosKbdRead
  70.  
  71.  
  72. ■ Example
  73.  
  74.   #include <fpclib.h>
  75.  
  76.   main()
  77.   {
  78.      printf( "Value of keypressed = %u  \n", BiosKbdGetElmt() );
  79.   }
  80.  
  81.   If Control-Break were pressed then zero would be displayed.  If the
  82.   'A' were pressed then 197 would be displayed: (197 - 132 = 65).
  83. ..page
  84. ..head03ABiosKbdHit
  85. ■ Description
  86.  
  87.   Reports if a keystroke is waiting to be read from the keyboard
  88.   buffer.
  89.  
  90.  
  91. ■ Summary
  92.  
  93.   Function BiosKbdHit : Boolean;
  94.  
  95.  
  96. ■ Remarks
  97.  
  98.   Using the BIOS services BiosKbdHit checks the keyboard status to
  99.   determine if a key is waiting to be read from the keyboard buffer.
  100.  
  101.  
  102. ■ See Also
  103.  
  104.   DosKbdHit
  105.  
  106.  
  107. ■ Example
  108.  
  109.   #include <fpclib.h>
  110.  
  111.   main()
  112.   {
  113.      while ( !BiosKbdHit() )
  114.         printf( "Keyboard buffer empty...\n" );
  115.   }
  116.  
  117.   This program will display the keyboard buffer empty phrase on a new
  118.   line until a key is pressed on the keyboard.
  119. ..page
  120. ..head03ABiosKbdRead
  121. ■ Description
  122.  
  123.   Read a character from the keyboard.
  124.  
  125.  
  126. ■ Summary
  127.  
  128.   Procedure BiosKbdRead( Var Ch : String );
  129.  
  130.   Ch          returns a string of length zero, one, or two bytes long
  131.               defining the key or key combination pressed from the
  132.               keyboard.
  133.  
  134.  
  135. ■ Remarks
  136.  
  137.   BiosKbdRead reads a single character from the keyboard buffer.
  138.   BiosKbdRead will return a zero, one, or two character string.  A
  139.   null string indicates that Ctrl- Break was pressed.  A one-character
  140.   string indicates a normal ascii character was read from the
  141.   keyboard.  A two-character string indicates a special extended
  142.   keyboard code.  Refer to appendix B for a list of the extended
  143.   keyboard codes.  The data type definition for BiosKbdRead is an
  144.   untyped variable using a minimum of three bytes.
  145.  
  146.  
  147. ■ See Also
  148.  
  149.   BiosKbdGetElmt, DosKbdGetElmt, DosKbdRead
  150. ..page
  151. ■ Example
  152.  
  153.   #include <fpclib.h>
  154.  
  155.   main()
  156.   {
  157.      char Ch[2];
  158.  
  159.      BiosKbdRead( Ch );
  160.      switch ( Ch[0] )
  161.         case  0 : printf( "Ctrl char pressed" );     break;
  162.         case 27 : printf( "Other key comb used" );   break;
  163.         default : if ( Ch[0] > 31 && Ch[0] < 128 )
  164.                      printf( "ASCII pressed" );
  165.      }
  166.   }
  167.  
  168.   In this example any key or key combination that is read from the
  169.   keyboard will be grouped into one of three categories.
  170.  
  171.   If Ch[1] is equal to the null byte and the length byte is equal to
  172.   two, then one of the control characters (0-31) was pressed.  This
  173.   includes the enter key, backspace, tab, and key combinations that
  174.   use the control and an ACSII character A-Z.  If Ch[1] is equal to
  175.   #27 then some other key combination was used, generally involving
  176.   the alt key or control key with one of the function keys or cursor
  177.   movement keys.  The string length will be two.  If Ch[1] is in the
  178.   range #32..#127 then an ASCII character was pressed.  The length
  179.   will also be one, where as in the other two possibilites the length
  180.   will be two.
  181. ..page
  182. ..head03ABiosKbdStat
  183. ■ Description
  184.  
  185.   Get the keyboard status byte
  186.  
  187.  
  188. ■ Summary
  189.  
  190.   Function BiosKbdStat : Intger;
  191.  
  192.  
  193. ■ Remarks
  194.  
  195.  
  196.   BiosKbdStat returns the keyboard status byte as follows:
  197.  
  198.                BITS
  199.   ─────────────────────────────────
  200.   | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
  201.   ─────────────────────────────────
  202.  
  203.    Bit   Bit Value    Key Pressed
  204.    ---   ---------    ──────────-
  205.     0        1        Right Shift
  206.     1        2        Left Shift
  207.     2        4        Control
  208.     3        8        Alternate
  209.  
  210.                        Key Mode
  211.                       ───────────
  212.     4       16        Scroll Lock
  213.     5       32        Num Lock
  214.     6       64        Caps Lock
  215.     7      128        Insert
  216.  
  217.   A one in the bit position means the condition is true and a zero in
  218.   the bit position means the condition is false.
  219. ..page
  220. ■ Example
  221.  
  222.   #include <fpclib.h>
  223.  
  224.   main()
  225.   {
  226.      int i,done = 0;
  227.  
  228.      VioInit();      /* need for ClrWin */
  229.  
  230.      while ( !done ) {
  231.         i = BiosKbdStat();
  232.         if ( BiosKbdHit() ) {
  233.  
  234.            if ( i & 2 )
  235.               done++;
  236.  
  237.            ClrWin( 1, 1, 80, 25, 7 );
  238.  
  239.           if ( i & 16 ) printf( "Scroll Lock ON \n" );
  240.           else          printf( "Scroll Lock OFF\n" );
  241.  
  242.           if ( i & 32 ) printf( "Num Lock ON \n" );
  243.           else          printf( "Num Lock OFF\n" );
  244.  
  245.           if ( i & 64 ) printf( "Caps Lock ON \n" );
  246.           else          printf( "Caps Lock OFF\n" );
  247.  
  248.           if ( i & 128 ) printf( "Insert ON \n" );
  249.           else           printf( "Insert OFF\n" );
  250.         }
  251.      }
  252.   }
  253.  
  254.   In this example everytime a key is pressed the screen is cleared and
  255.   the status for the Scroll Lock, Insert, Caps Lock and Num Lock keys
  256.   is displayed in the upper left corner.  This routine will not
  257.   terminate until a key is pressed with the left shift key held down.
  258. ..page
  259. ..head03ADosKbdClr
  260. ■ Description
  261.  
  262.   Clear the keyboard buffer.
  263.  
  264.  
  265. ■ Summary
  266.  
  267.   Procedure DosKbdClr;
  268.  
  269.  
  270. ■ Remarks
  271.  
  272.   DosKbdClr uses DOS to clear any characters in the keyboard buffer
  273.   waiting to be read.
  274.  
  275.  
  276. ■ See Also
  277.  
  278.   BiosKbdClr
  279.  
  280.  
  281. ■ Example
  282.  
  283.   #include <fpclib.h>
  284.  
  285.   main()
  286.   {
  287.      int Ch;
  288.  
  289.      DosKbdClr();
  290.      Ch = GetKey();
  291.   }
  292.  
  293.   In this example the keyboard buffer is flushed before reading a
  294.   keystroke from the keyboard.
  295. ..page
  296. ..head03ADosKbdGetElmt
  297. ■ Description
  298.  
  299.   Returns an integer value for the key pressed on the keyboard.
  300.  
  301.  
  302. ■ Summary
  303.  
  304.   Function DosKbdGetElmt : Integer;
  305.  
  306.  
  307. ■ Remarks
  308.  
  309.   DosKbdGetElmt will return an integer in the range of 0-388.  Use
  310.   Appendix C to find the keyboard element code this function returns
  311.   for a particular key pressed on the keyboard.
  312.  
  313.   Key combinations using the control key with an alpha character and
  314.   all other ascii characters will be offset by 132.
  315.  
  316.  
  317. ■ See Also
  318.  
  319.   BiosKbdGetElmt, BiosKbdRead, DosKbdRead
  320.  
  321.  
  322. ■ Example
  323.  
  324.   #include <fpclib.h>
  325.  
  326.   main()
  327.   {
  328.      printf( "Value of keypressed = %u\n", DosKbdGetElmt() );
  329.   }
  330.  
  331.   If Control-Break were pressed then zero would be displayed.  If the
  332.   'A' were pressed then 197 would be displayed: (197 - 132 = 65).
  333. ..page
  334. ..head03ADosKbdHit
  335. ■ Description
  336.  
  337.   Reports if a keystroke is waiting to be read from the keyboard
  338.   buffer.
  339.  
  340.  
  341. ■ Summary
  342.  
  343.   Function DosKbdHit : Boolean;
  344.  
  345.  
  346. ■ Remarks
  347.  
  348.   Using the DOS services DosKbdHit checks the keyboard status to
  349.   determine if a key is waiting to be read from the keyboard buffer.
  350.  
  351.  
  352. ■ See Also
  353.  
  354.   BiosKbdHit
  355.  
  356.  
  357. ■ Example
  358.  
  359.   #include <fpclib.h>
  360.  
  361.   main()
  362.   {
  363.      while ( !DosKbdHit() )
  364.         printf( "Keyboard buffer empty...\n" );
  365.   }
  366.  
  367.   This program will display the keyboard buffer empty phrase on a new
  368.   line until a key is pressed on the keyboard.
  369. ..page
  370. ..head03ADosKbdRead
  371. ■ Description
  372.  
  373.   Read a character from the keyboard.
  374.  
  375.  
  376. ■ Summary
  377.  
  378.   Procedure DosKbdRead( Var Ch : String );
  379.  
  380.   Ch          returns a string of length zero, one, or two bytes long
  381.               defining the key or key combination pressed from the
  382.               keyboard.
  383.  
  384.  
  385. ■ Remarks
  386.  
  387.   DosKbdRead reads a single character from the keyboard buffer.
  388.   DosKbdRead will return a zero, one, or two character string.  A null
  389.   string indicates that Ctrl- Break was pressed.  A one-character
  390.   string indicates a normal ascii character was read from the
  391.   keyboard.  A two-character string indicates a special extended
  392.   keyboard code.  Refer to appendix B for a list of the extended
  393.   keyboard codes.  The data type definition for DosKbdRead is an
  394.   untyped variable using a minimum of three bytes.
  395.  
  396.  
  397. ■ See Also
  398.  
  399.   BiosKbdGetElmt, BiosKbdRead, DosKbdGetElmt
  400. ..page
  401. ■ Example
  402.  
  403.   #include <fpclib.h>
  404.  
  405.   main()
  406.   {
  407.      char Ch[2];
  408.  
  409.      DosKbdRead();
  410.      switch ( Ch[0] ) {
  411.         case  0 : printf( "Ctrl char pressed\n" );    break;
  412.         case 27 : printf( "Other key comb used\n" );  break;
  413.         default : if ( Ch[0] > 31 && Ch[0] < 128 )
  414.                      printf( "ASCII pressed\n" );
  415.      }
  416.   }
  417.  
  418.   In this example any key or key combination that is read from the
  419.   keyboard will be grouped into one of three categories.
  420.  
  421.   If Ch[1] is equal to the null byte and the length byte is equal to
  422.   two, then one of the control characters (0-31) was pressed.  This
  423.   includes the enter key, backspace, tab, and key combinations that
  424.   use the control and an ACSII character A-Z.  If Ch[1] is equal to
  425.   #27 then some other key combination was used, generally involving
  426.   the alt key or control key with one of the function keys or cursor
  427.   movement keys.  The string length will be two.  If Ch[1] is in the
  428.   range #32..#127 then an ASCII character was pressed.  The length
  429.   will also be one, where as in the other two possibilites the length
  430.   will be two.
  431. ..page
  432. ..head03AGetKey
  433. ■ Description
  434.  
  435.   Returns a keystroke and map it into a keyboard element number for
  436.   EditSt.
  437.  
  438.  
  439. ■ Summary
  440.  
  441.   Function GetKey : Integer;
  442.  
  443.  
  444. ■ Remarks
  445.  
  446.   This function may call other functions and procedures if it so
  447.   desires. The only restriction is that it must return an integer
  448.   value that is in the table found in Appendix C if the function
  449.   EditSt is used.  If EditSt is not used the only restriction is that
  450.   an integer must be returned.
  451.  
  452.  
  453. ■ Example
  454.  
  455.   #include <fpclib.h>
  456.  
  457.   INT GetKey( void )
  458.   {
  459.      int i;
  460.  
  461.      while ( !DosKbdHit() ) {
  462.         FillRowChar( 1, 25, 80, ' ' );
  463.  
  464.         i = BiosKbdStat();
  465.  
  466.         if ( i & 16  ) ColorMsg(  1, 25, 7, "Scroll" );
  467.         if ( i & 32  ) ColorMsg(  8, 25, 7, "Num"    );
  468.         if ( i & 64  ) ColorMsg( 12, 25, 7, "Caps"   );
  469.         if ( i & 128 ) ColorMsg( 17, 25, 7, "Insert" );
  470.      }
  471.      return( BiosKbdGetElmt() );
  472.   }
  473.  
  474.   main()
  475.   {
  476.      printf( "Key element number = %u\n", GetKey() );
  477.   }
  478.  
  479.   This example polls the keyboard, gets the keyboard status byte and
  480.   displays the status for four keys while a key has not been pressed.
  481.   Once a key has been pressed on the keyboard the BiosKbdGetElmt
  482.   function is called to get the keyboard element number.
  483. ..page
  484.