I've got a weird one for the experts here.

I'm running an old DOS (originally compiled with TP) Pascal program that uses the CRT unit. It has several places where it uses KeyPressed/ReadKey to pause a screen until the user responds. It uses the same combination to read user input. However, it appears to be a random function which determines whether (or when?) a key is detected.

For instance, when the program begins, it sets up the screen, (clears, displays a title at the top, and displays some initial messages, then uses "KeyPressed/ReadKey" to clear the keyboard buffer. then displays a "Press any key to continue:" prompt and waits for a successful "KeyPressed" (using "REPEAT UNTIL KeyPressed;" and then discards the return from the following ReadKey.

The trouble is that after that "Press any key to continue" prompt comes up, I may need to press anywhere from 1 to 10 keys to get the "KeyPressed" routine to see it. (I inserted logging statements between each line of code.)

Of course, being a (moderately) creative sort, I threw together a small test program that had just the elements I was interested in. That program worked! So there is apparently some interaction with something (WinCRT? DOS? something else?) which is making KeyPressed not work in the big old DOS program while it works just fine in the small test program.

Any ideas? (Note, please don't dig too much into this on my behalf--I'm hoping someone else has run into this issue and figured it out. Now that I know how to do it, I'm almost done with another DLL which does my keyboard IO using the standard C libraries. In other words, I'm replacing all my "KeyPressed" and "ReadKey" calls with "CheckKey" and "GetKey" calls respectively which, in turn, respectively call the C standard library <conio.h> functions "_kbhit" and "getch". But if there is a simple fix to the KeyPressed issue, then my IO.pp unit can simply have an implementation that calls KeyPressed and ReadKey instead of using the DLL.)

Thanks in advance.

Lowell C. Savage
[EMAIL PROTECTED]
505-667-6964 (office/msg)
360-961-8965 (cell/msg)
505-667-4341 (shared fax)


_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to