program keytest(input,output); { by mtie 3/7/96 keytest is an example of a pascal program that continues doing other things while waiting for keyboard input from the user. In this program, "blah" is displayed over and over again until the user enters the character "q" to quit the program. The number of characters typed is counted and displayed at the end of the program. keytest is compiled with the command gpcgraphics keytest keytest.p One more thing to note: DO NOT USE READ OR READLN BETWEEN TTYCBREAK AND TTYNORM. } import graphics; var c : char; counter : integer; begin c := ' '; counter := 0; inittty; {initializes the terminal} ttycbreak; {Prevents chars from echoing to screen and traps chars in the} {buffer when typed. Only kbhit and getch can be used for } {input after this is called. } while (c <> 'q') do {The loop waits for a 'q', but note that none of the typed chars are } {written to the screen. You must use a "write" to write output. } begin if (kbhit) then begin c := getch; {getch reads in chars from the input buffer } counter := counter+1; end; write('blah '); end; ttynorm; {This un-does ttycbreak. The input buffer writes directly to } {the terminal. read and readln can be used again.} writeln; writeln('you typed in ',counter:4,' characters.'); end.