Source Code For Using Function Keys or Cursor Keys - Help :) 
Author Message
 Source Code For Using Function Keys or Cursor Keys - Help :)

hi  there,
     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. :)

cheers,
  Zule



Sat, 14 Nov 1998 03:00:00 GMT  
 Source Code For Using Function Keys or Cursor Keys - Help :)



Quote:
>hi  there,
>     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. :)

Dear Zule
        Below I have enclosed a program written in Turbo Pascal which
allows the use of function keys, and cursors keys.  It shows how it is
possible to use both of them and it should be easy for you to adapt it
for yourself, as I have been able to.  I must mention though that this
particular program was originally obtained from a friend, but I'm sure
they will not mind me passing it on.

program function_keys;
uses crt;
var ch : char;
begin
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');
            61 : writeln('Function key 3');
            62 : writeln('Function key 4');
            63 : writeln('Function key 5');
            64 : writeln('Function key 6');
            65 : writeln('Function key 7');
            66 : writeln('Function key 8');
            67 : writeln('Function key 9');
            68 : writeln('Function key 10');

            72 : writeln('up-arrow');
            75 : writeln('left-arrow');
            77 : writeln('right-arrow');
            80 : writeln('down-arrow');

       end;
   until ord(ch) = 27;  {escape key}
end.

I hope this will be helpful, for the first part of your question anyway.

Neil Jaques

--
Neil Jaques
01420 474290



Sat, 14 Nov 1998 03:00:00 GMT  
 Source Code For Using Function Keys or Cursor Keys - Help :)

Quote:
> >     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
> allows the use of function keys, and cursors keys.  It shows how it is
> possible to use both of them and it should be easy for you to adapt it
> for yourself, as I have been able to.  I must mention though that this
> particular program was originally obtained from a friend, but I'm sure
> they will not mind me passing it on.

> program function_keys;
> uses crt;
> var ch : char;
> begin
> 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');
>             61 : writeln('Function key 3');
>             62 : writeln('Function key 4');
>             63 : writeln('Function key 5');
>             64 : writeln('Function key 6');
>             65 : writeln('Function key 7');
>             66 : writeln('Function key 8');
>             67 : writeln('Function key 9');
>             68 : writeln('Function key 10');
>             72 : writeln('up-arrow');
>             75 : writeln('left-arrow');
>             77 : writeln('right-arrow');
>             80 : writeln('down-arrow');
>        end;
>    until ord(ch) = 27;  {escape key}
> end.

> I hope this will be helpful, for the first part of your question anyway.
>   This code has a serious problem, IMHO: you're using the same variable

(CH) for both the initial ReadKey and the reading of the scan code.  
Let's examine what happens if the user presses "M", instead of the
RightArrow key: this code will act as though the RightArrow key _was_
pressed.  Is that what you want/expect to happen?
   Any code which processes key strokes should be prepared to handle
_any_ user action, valid or not.  In the processing of the
extended/special keys, you must, of course, do the 2nd ReadKey to fetch
the scan code of the key, but you really should separate the action of
that scan code value from other legitimate key strokes, right?  This can
be easily corrected - by using a 2nd char variable and using it as the
Case variable:

  C1 := ReadKey;
  case C1 of
   #00 : begin
           C2 := ReadKey;  { fetch scan code and process it }
           case C2 of
            #77 : rt_arrow;
            etc.
           end
         end;
   #77 : UPPER_M;
   etc.
  end



Sat, 14 Nov 1998 03:00:00 GMT  
 Source Code For Using Function Keys or Cursor Keys - Help :)


Quote:

>>        case ord(ch) of
>>             59 : writeln('Function key 1');
>>             60 : writeln('Function key 2');

That fragment would IMHO be better put as
       case ch of
          #59 : writeln('Function key 1');
          #60 : writeln('Function key 2'); ;
ch can be used as is - of course the code generated should be the same -
as shown in fact below by Mike.

Quote:
>  C1 := ReadKey;
>  case C1 of
>   #00 : begin
>           C2 := ReadKey;  { fetch scan code and process it }
>           case C2 of
>            #77 : rt_arrow;
>            etc.
>           end
>         end;
>   #77 : UPPER_M;
>   etc.
>  end

C1 & C2 are in fact superfluous, and omitting them makes it clearer that
each result of ReadKey is only used once - and it could well be wise to
UpCase the first:

  case UpCase(ReadKey) of
   #00 : begin
           case ReadKey of  { fetch scan code and process it }
            #77 : rt_arrow;
            etc.
           end
         end;
   #77 : UPPER_M;
   etc.
  end

--

    Home Page under construction.



Sun, 15 Nov 1998 03:00:00 GMT  
 Source Code For Using Function Keys or Cursor Keys - Help :)

Quote:
>>    repeat
>>        ch := readkey;
>>        if ord(ch) = 0
>>        then ch := readkey;
>>        case ord(ch) of
>>             59 : writeln('Function key 1');
>>             60 : writeln('Function key 2');
>>   This code has a serious problem, IMHO: you're using the same variable
>(CH) for both the initial ReadKey and the reading of the scan code.  
>Let's examine what happens if the user presses "M", instead of the
>RightArrow key: this code will act as though the RightArrow key _was_
>pressed.  Is that what you want/expect to happen?

If the user presses "M", then there is no scan code to worry about.  The
second ch only gets mucked with if the scan code is 0, which will only happen
on the extended keys...

--
BCNU
Daniel J. Wojcik
http://147.35.241.5/mindless/mindless.htm
Life and Death are things you just do when you're bored



Mon, 16 Nov 1998 03:00:00 GMT  
 Source Code For Using Function Keys or Cursor Keys - Help :)

Quote:
> >>    repeat
> >>        ch := readkey;
> >>        if ord(ch) = 0
> >>        then ch := readkey;
> >>        case ord(ch) of
> >>             59 : writeln('Function key 1');
> >>             60 : writeln('Function key 2');

> >>   This code has a serious problem, IMHO: you're using the same variable
> >(CH) for both the initial ReadKey and the reading of the scan code.
> >Let's examine what happens if the user presses M, instead of the
> >RightArrow key: this code will act as though the RightArrow key _was_
> >pressed.  Is that what you want/expect to happen?

> If the user presses M, then there is no scan code to worry about.  The
> second ch only gets mucked with if the scan code is 0, which will only happen
> on the extended keys...
>    No.  Perhaps I didn't make myself clear: the 1st ReadKey, when the

user inputs M, returns #77; when the user presses UpArrow, the 2nd
ReadKey is invoked (because the value of CH is #00), and the 2nd readkey
returns #77.  The Case statement is then executed - whether the 2nd
ReadKey is processed or not!  
   This code results in the Case statement processing both UpArrow and M
as though it's the UpArrow...because the Case makes no distinction
between the CH value being from the M (the 1st ReadKey) or the UpArrow
being pressed.  Yes, if the user presses M, the 2nd ReadKey is not
engaged, but the Case statement is executed, using the value of CH, in
all events.  Therefore, the Case statement will process both M and
UpArrow...as though they're both UpArrow.


Fri, 20 Nov 1998 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Source Code For Using Function Keys or Cursor Keys - H

2. Using the Function Keys and The Escape Key

3. Reading function/cursor keys

4. using enter key instead of tab key for data entry

5. Using function keys

6. Source Code for a Key Capture Program

7. Removing a Key using code?

8. !!! Help, Cursor Keys

9. key release and key pressed help?

10. Help on Arrow Keys--Handy tool for all keys

11. read cursor keys

12. read cursor key

 

 
Powered by phpBB® Forum Software