Subj : FPC Oneliners.
To   : Joseph Larsen
From : mark lewis
Date : Thu Jun 09 2016 12:20 pm


09 Jun 16 01:56, you wrote to me:

ml>> remember to keep it simple and straightforward...

JL> I think I know the problem.

[trim]

JL> See the "#8 : begin" ? I don't think that's right. Any idea what I
JL> change it to?

that's a zero, not an eight... that zero is the null character and must be used
to detect double-character keycodes like the F-keys and the arrow keys...

change your routine to a completely stand alone program so you can test it
easier... watch your formatting, too... below is such a standalone with an
added key displaying routine so you can see which key has been pressed... you
can remove that one entire routine and the two calls to it and the program
should operate like what you already have that you are having troubles with...

WARNING: some keys may not return the expected codes (eg: the END key) and
others may be taken over by your terminal (eg: ALT-F?? keys)...

===== snip test_position.pas =====
program test_position;

uses crt;

var
 ch1 : char;
 ch2 : char;

procedure displaykey(var thechar1, thechar2 : char);

begin
 case thechar1 of
   #00 : begin
           write('  double character key - ');
           case thechar2 of
             #16 : writeln('ALT-Q');
             #17 : writeln('ALT-W');
             #18 : writeln('ALT-E');
             #19 : writeln('ALT-R');
             #20 : writeln('ALT-T');
             #21 : writeln('ALT-Y');
             #22 : writeln('ALT-U');
             #23 : writeln('ALT-I');
             #24 : writeln('ALT-O');
             #25 : writeln('ALT-P');

             #30 : writeln('ALT-A');
             #31 : writeln('ALT-S');
             #32 : writeln('ALT-D');
             #33 : writeln('ALT-F');
             #34 : writeln('ALT-G');
             #35 : writeln('ALT-H');
             #36 : writeln('ALT-J');
             #37 : writeln('ALT-K');
             #38 : writeln('ALT-L');

             #44 : writeln('ALT-Z');
             #45 : writeln('ALT-X');
             #46 : writeln('ALT-C');
             #47 : writeln('ALT-V');
             #48 : writeln('ALT-B');
             #49 : writeln('ALT-N');
             #50 : writeln('ALT-M');

             #59 : writeln('F1');
             #60 : writeln('F2');
             #61 : writeln('F3');
             #62 : writeln('F4');
             #63 : writeln('F5');
             #64 : writeln('F6');
             #65 : writeln('F7');
             #66 : writeln('F8');
             #67 : writeln('F9');
             #68 : writeln('F10');

             #71 : writeln('HOME');
             #72 : writeln('UPARR');
             #73 : writeln('PGUP');

             #75 : writeln('LFARR');

             #77 : writeln('RTARR');

             #79 : writeln('END');
             #80 : writeln('DNARR');
             #81 : writeln('PGDN');
             #82 : writeln('INSERT');
             #83 : writeln('DELETE');

             #104 : writeln('ALT-F1');
             #105 : writeln('ALT-F2');
             #106 : writeln('ALT-F3');
             #107 : writeln('ALT-F4');
             #108 : writeln('ALT-F5');
             #109 : writeln('ALT-F6');
             #110 : writeln('ALT-F7');
             #111 : writeln('ALT-F8');
             #112 : writeln('ALT-F9');
             #113 : writeln('ALT-F10');

             #133 : writeln('F11');
             #134 : writeln('F12');

             #139 : writeln('ALT-F11');
             #140 : writeln('ALT-F12');
           else
             writeln('  unknown double character key = #',ord(thechar1),'
#',ord(thechar2));
           end; {case thechar2}
         end; {begin thechar1 = #00}
 else
   begin
     write('  single character key - ');
     case thechar1 of
       #01 : writeln('CTRL-A');
       #02 : writeln('CTRL-B');
       #03 : writeln('CTRL-C');
       #04 : writeln('CTRL-D');
       #05 : writeln('CTRL-E');
       #06 : writeln('CTRL-F');
       #07 : writeln('CTRL-G');
       #08 : writeln('BCKSPC');
       #09 : writeln('TAB');
       #10 : writeln('LF');
       #11 : writeln('VT');
       #12 : writeln('FF');
       #13 : writeln('ENTER');
       #14 : writeln('CTRL-N');
       #15 : writeln('CTRL-O');
       #16 : writeln('CTRL-P');
       #17 : writeln('CTRL-Q');
       #18 : writeln('CTRL-R');
       #19 : writeln('CTRL-S');
       #20 : writeln('CTRL-T');
       #21 : writeln('CTRL-U');
       #22 : writeln('CTRL-V');
       #23 : writeln('CTRL-W');
       #24 : writeln('CTRL-X');
       #25 : writeln('CTRL-Y');
       #26 : writeln('CTRL-Z');
       #27 : writeln('ESC');
       #28 : writeln('FS');
       #29 : writeln('GS');
       #30 : writeln('RS');
       #31 : writeln('US');
       #32 : writeln('SPACE');
     else
       writeln(chr(byte(thechar1)),' = #',ord(thechar1));
     end; {case thechar1}
   end; {begin else}
 end;
end;

Begin
 writeln('>> do show routine <<');
 writeln('press any key to continue or ENTER to quit.');
 Repeat
   ch1 := #00;
   ch2 := #00;
   if keypressed then
     begin
       writeln('>> display onen.ans here <<');
       ch1 := readkey;
       case ch1 of
         #00 : begin
                 if keypressed then
                   begin
                     ch2 := readkey;
                     displaykey(ch1,ch2);
                     case ch2 of
                       #80 : writeln('>> do bot_bar routine <<');
                       #72 : writeln('>> do top_bar routine <<');
                     end; {case ch2}
                   end; {if keypressed}
               end; {begin ch1 = #00}
       else
         displaykey(ch1,ch2);
       end; {case ch1}
     end; {if keypressed}
 until ch1=#13;
end.
===== snip =====

)\/(ark

Always Mount a Scratch Monkey

... 48. Sympathy is a crutch, never fake a limp.
---
* Origin:  (1:3634/12.73)