home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 15 / CDACTUAL15.iso / cdactual / program / pascal / PASLIBR.ZIP / CH3_1.DOC < prev    next >
Encoding:
Text File  |  1991-03-15  |  11.7 KB  |  475 lines

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