Source Code For Using Function Keys or Cursor Keys - H

On Tue, 28 May 1996 20:00:56 +0100 Neil Jaques wrote:

Quote
>In article <4odqug$...@lantana.singnet.com.sg>, Zule writes
>>     I doing some school project on writing program in pascal
>>(DOS/Version 7).   I have plans to make the menu selection by using
>>the cursor key (Left,Right,Up,Down) & some Function Keys.  Could
>>anyone assist me?  Could you send me the ansi equivalent of that key?
>>  Next, after making a window in pascal using the command
>>'window(X1,Y1,X2,Y2)' ....how do i make the cursor move outside that
>>window?...do i have to use the 'gotoxy' command? or is there a way of
>>closing that window?   Thx in advance.  Greatly appreciated. :)

>        Below I have enclosed a program written in Turbo Pascal which
[...]
>writeln('In Function Keys Program');
>   repeat
>       ch := readkey;
>       if ord(ch) = 0
>       then ch := readkey;

>       case ord(ch) of

>            59 : writeln('Function key 1');
>            60 : writeln('Function key 2');

[...]

Better:
------------------
  repeat
    i := Ord( ReadKey );
    if i = 0 then i := 1000 + ReadKey;
    case i of
      1059: writeLn( 'F1' );
      { etc }
-------------------

Why?
Example: Key 'A' = #$41 = #65, and your program response: 'Function key 7'

------------------------
Program TestKeyboardCodes;

var c: char; i: integer;

begin
  while KeyPressed do c := ReadKey; {clear buffer}
  repeat
    c := ReadKey;
    case c of
           #0: begin
                 c := ReadKey;
                 WriteLn( '0+', Ord( c ) )
               end
      #1..#31: WriteLn( '^', Chr( Ord( '@' ) + Ord( 'c' ) ), ':', Ord( c ) );
         else: WriteLn( c, ':', Ord( c ) )
    end
  until c = ^[ {ESC}
end.

--

/------------------------------------------------------------------
Gregorio Kus    Gr...@RMnet.it                 Gr...@{*word*104}space.org
ROMA, Italy     http://www.RMnet.it/~grego     Gr...@FreeNet.hut.fi