Testing the “Keyboard” unit on my Mac.

CODE:
{$mode delphi}{$H+} // DOES NOT MATTER IF THIS IS INCLUDED OR NOT //

uses
   keyboard;

var
   K:TKeyEvent;

begin
   InitKeyboard;
   While GetKeyEventChar(K)<>'q' do begin
      If Keypressed then begin
         K:=GetKeyEvent;
         K:=TranslateKeyEvent(K);
         Write('* Got key event with ');
         Case GetKeyEventFlags(K) of
            kbASCII   :Writeln('ASCII key');
            kbUniCode :Writeln('Unicode key');
            kbFnKey   :Writeln('Function key');
            kbPhys    :Writeln('Physical key');
            kbReleased:Writeln('Released key event');
         end;
         Writeln('Got key : ',KeyEventToString(K),' #',Ord(GetKeyEventChar(K)));
      End;
   End;
   DoneKeyboard;
end.

I found so far using iTerm2:
        Function Key - working
        Ctrl-A must be pressed twice to return #$01
        Ctrl-Z must be pressed twice to return #$1A
        All other Ctrl sequences worked fine
        Alt-Left returns Key with scancode 39680
        Alt-Right returns Key with scancode 40192
        Alt-Up returns Key with scancode 38912
        Alt-Down returns Key with scancode 40960
        However, Alt-Key sequences are not returning as Unicode (as I thought 
they should), instead it lops twice and gives me #195 then #165 for Alt-A, 
while Alt-[ returns #226, #128, #156 as “ASCII key”.

Switching to Apple’s Terminal:
        Function Key - working
        Ctrl-A must be pressed twice to return #$01
        Ctrl-Z must be pressed twice to return #$1A
        All other Ctrl sequences worked fine
        Alt-A works fine.
DIFF:   Alt-Up Arrow, Alt-Down Arrow does not return anything, yet…
        Alt-Left returns Key with scancode 12288
        Alt-Right returns Key with scancode 8448

* Obviously, I am seeing a variance based upon the terminal app. Is this 
expected? I never see “released key event”, is that expected in a terminal also?

Also on both terminals, if I do Ctrl-A release, then Alt-A, I see “Got key : 
SHIFT" and the ALT-A output.

Ozz
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to