home *** CD-ROM | disk | FTP | other *** search
- program keydemo;
- {$C-}
- { By Orville Jenkins / Panther Associates / Dallas Ft. Worth }
- { These routines are for Public Domain and may be used for fun or PROFIT!!! }
- var
- SpecialKey : boolean; { used in demo below }
- command : char; { used in demo below }
-
- { This program demonstrates a TURBO Pascal Procedure "INKEY". }
- { INKEY is a procedure which emulates the BASIC function "INKEY". }
-
- FUNCTION INKEY (var special : boolean; var KeyChar : char) : boolean;
- { Not-so-humbly offered to the TURBO Users Group by }
- { Orville Jenkins / Panther Associates / Dallas-Ft. Worth }
-
- { INKEY returns TRUE if a key has been pressed. }
- { IF the parameter "special" is TRUE the character is one of the }
- { two-code Keys such as F1-F10 etc. and the parameter "KEYCHAR" }
- { is the second code which is what you're interested in. }
-
- (* IMPORTANT: If you want "key-ahead" buffering of keystrokes *)
- (* then you must turn off the compiler directive "C" by saying *)
- (* {$C-}. Without this, ie if you have {$C+} set then DOS will *)
- (* throw away keystrokes which haven't yet been read in. *)
-
- var
- dosrec : record
- ax, bx, cx, dx, bp, si, di, ds, es, flags : integer;
- end;
-
- begin {Function Inkey}
- if keypressed then
- begin
- dosrec.ax := $0800;
- msdos(dosrec);
- keychar := chr(lo(dosrec.ax));
- inkey := true;
- if ord(keychar) = 27 then
- begin
- special := true;
- dosrec.ax := $0800;
- msdos(dosrec);
- keychar := chr(lo(dosrec.ax));
- end
- else
- special := false
- end
- else
- begin { no character is ready }
- inkey := false;
- special := false;
- end;
- end; {Function Inkey}
-
- Begin {Main Program}
-
- clrscr;
- writeln('INKEY DEMO - Press any key - Press F-10 to quit');
- writeln;
- command := #00;
-
- repeat
- if inkey(specialkey,command) then
- begin
- if specialkey then
- writeln('That''s a SPECIAL key - the ascii code is ',ord(command) )
- else
- writeln('That''s a REGULAR key - the ascii code is ',ord(command));
-
- writeln;
- writeln;
- if command <> #68 then
- writeln('INKEY DEMO - Pressss any key - Presss F-10 to quit ');
- writeln;
- end;
- until command = #68; {F-10 key}
-
- end.
-