home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / keyboard / break / ctrlc.bug < prev   
Encoding:
Text File  |  1988-07-31  |  3.1 KB  |  77 lines

  1.              TURBO PASCAL AND SIDEKICK
  2.                  (Control-C Issues)                29 Jul 85
  3.  
  4. Pardon any confusion I caused with my previous message
  5. regarding Ctrl-C problems with Turbo Pascal and Sidekick,
  6. but after further investigation I have found the following:
  7.  
  8.    I had been trying to do two things:  (1) Accurately detect
  9. function and special keys, and (2) detect and process Ctrl-C.
  10. The problem that I have with the standard Turbo input routine
  11. is that when input is buffered, one cannot tell the difference
  12. between a function key and an ESC followed by another key!!
  13. Therefore I redefined CONINPTR to point to a function which
  14. called DOS Function 7 (Direct Keyboard Input Without Echo).
  15. This worked great (now I checked for a #00 instead of a #27
  16. to detect function keys), except that if Sidekick was resident
  17. Ctrl-C would never make it to my program; rather a CRLF
  18. followed by a '^C' would be sent to the display!!  This was
  19. distressing because when CONINPTR was NOT redefined (and break
  20. processing was turned off ( {$C-} ), Ctrl-C was being detected
  21. correctly.  On a hunch I decided to try Function 6 (Direct
  22. Keyboard/Display I/O).  This works great!  The following code
  23. is what I now use in all of my programs:
  24.  
  25. type
  26.    dos_parms = record case integer of
  27.       1: (AX,BX,CX,DX,BP,SI,DI,DS,ES,Flags: Integer);
  28.       2: (AL,AH,BL,BH,CL,CH,DL,DH         : Byte);
  29.    end;
  30. var
  31.    parm: dos_parms;
  32.  
  33. function cin6:char;
  34. {DOS Function #6: Direct Keyboard/Display I/O (without echo
  35.                    OR Ctrl-C check}
  36. begin
  37.    with parm do
  38.    begin
  39.       repeat
  40.          AX := $0600;
  41.          DL := $FF;                 {read keyboard version}
  42.          msdos(parm);
  43.       until (flags and ZF) = 0;     {until character present}
  44.       cin6 := Chr (AL);
  45.    end;
  46. end;
  47.  
  48. {*** this statement goes in intitialization code ***}
  49.    coninptr :=ofs(cin6);
  50.  
  51. Now simply use the standard keyboard I/O routines.  For example,
  52.    READ (KBD,CH);
  53. to read a character from the keyboard without echo.  The test
  54.    IF (CH = #27) AND KEYPRESSED THEN
  55. which is currently used to check for function keys, can now be
  56. written simply as:
  57.    IF (CH = #0) THEN
  58. and Escape (#27) can be treated like a standard character.
  59.  
  60. One last note: turning off Ctrl-C has an additional benefit not
  61. mentioned in the Turbo ref manual.  In addition to turning off
  62. the check for Ctrl-C break, it allows the keystrokes to be
  63. buffered on input.  With Ctrl-C on  {$C+},  Turbo checks for
  64. Control-C input and at the same time FLUSHES the input buffer
  65. about every 18 timer ticks (I think, though it may be every
  66. timer tick).  With Ctrl-C off  {$C-},  Turbo allows buffering
  67. of the keystrokes which is very useful for most applications.
  68. If this buffering is not desired, a FLUSH_INPUT routine could
  69. be written to be called just before any input is desired.  The
  70. routine would simply read and discard characters as long as
  71. KEYPRESSED is true.
  72.  
  73. Hope this helps others avoid the confusion I experienced in
  74. working this problem out.  If anyone has any questions/comments
  75. I can be reached at The RidgeRunner  (703)-491-7054.
  76.                     -- Greg Brunet
  77.