Browse Source

* fixes from Maarten Bekers

peter 26 years ago
parent
commit
2e8c087cf4
1 changed files with 62 additions and 14 deletions
  1. 62 14
      rtl/win32/crt.pp

+ 62 - 14
rtl/win32/crt.pp

@@ -432,8 +432,10 @@ End;
 var
 var
    ScanCode : char;
    ScanCode : char;
    SpecialKey : boolean;
    SpecialKey : boolean;
+   DoingNumChars: Boolean;
+   DoingNumCode: Byte;
 
 
-Function RemapScanCode (ScanCode: byte; CtrlKeyState: byte): byte;
+Function RemapScanCode (ScanCode: byte; CtrlKeyState: byte; keycode:longint): byte;
   { Several remappings of scancodes are necessary to comply with what
   { Several remappings of scancodes are necessary to comply with what
     we get with MSDOS. Special Windows keys, as Alt-Tab, Ctrl-Esc etc.
     we get with MSDOS. Special Windows keys, as Alt-Tab, Ctrl-Esc etc.
     are excluded }
     are excluded }
@@ -468,7 +470,16 @@ begin
   CtrlKey := ((CtrlKeyState AND
   CtrlKey := ((CtrlKeyState AND
             (RIGHT_CTRL_PRESSED OR LEFT_CTRL_PRESSED)) > 0);
             (RIGHT_CTRL_PRESSED OR LEFT_CTRL_PRESSED)) > 0);
   ShiftKey := ((CtrlKeyState AND SHIFT_PRESSED) > 0);
   ShiftKey := ((CtrlKeyState AND SHIFT_PRESSED) > 0);
-  if AltKey then
+  if AltKey then begin
+    Case KeyCode of
+      VK_NUMPAD0 ..
+      VK_NUMPAD9    : begin
+                       DoingNumChars := true;
+                       DoingNumCode := Byte((DoingNumCode * 10) + (KeyCode - VK_NUMPAD0));
+                      end;
+    end; { case }
+
+
     case ScanCode of
     case ScanCode of
     // Digits, -, =
     // Digits, -, =
     $02..$0D: inc(ScanCode, $76);
     $02..$0D: inc(ScanCode, $76);
@@ -482,6 +493,7 @@ begin
     $1C:      Scancode := $A6;   // Enter
     $1C:      Scancode := $A6;   // Enter
     $35:      Scancode := $A4;   // / (keypad and normal!)
     $35:      Scancode := $A4;   // / (keypad and normal!)
     end
     end
+   end
   else if CtrlKey then
   else if CtrlKey then
     case Scancode of
     case Scancode of
     // Tab key
     // Tab key
@@ -513,6 +525,7 @@ function KeyPressed : boolean;
 var
 var
   nevents, nread, i: longint;
   nevents, nread, i: longint;
   buf : TINPUTRECORD;
   buf : TINPUTRECORD;
+  AltKey: Boolean;
 begin
 begin
   KeyPressed := FALSE;
   KeyPressed := FALSE;
   if ScanCode <> #0 then
   if ScanCode <> #0 then
@@ -527,19 +540,54 @@ begin
         if buf.EventType = KEY_EVENT then
         if buf.EventType = KEY_EVENT then
          if buf.KeyEvent.bKeyDown then
          if buf.KeyEvent.bKeyDown then
           begin
           begin
+            { Alt key is VK_MENU }
+            { Capslock key is VK_CAPITAL }
+
+            AltKey := ((Buf.KeyEvent.dwControlKeyState AND
+                          (RIGHT_ALT_PRESSED OR LEFT_ALT_PRESSED)) > 0);
+            if (Buf.KeyEvent.wVirtualKeyCode in [VK_SHIFT, VK_MENU, VK_CONTROL,
+                                                VK_CAPITAL, VK_NUMLOCK,
+                                                VK_SCROLL]) then
+              begin
+                { Discard this key }
+              end
+                else begin
             KeyPressed := TRUE;
             KeyPressed := TRUE;
+
             if ord(buf.KeyEvent.AsciiChar) = 0 then
             if ord(buf.KeyEvent.AsciiChar) = 0 then
              begin
              begin
                SpecialKey := TRUE;
                SpecialKey := TRUE;
-               ScanCode := Chr(RemapScanCode(Buf.KeyEvent.wVirtualScanCode, Buf.KeyEvent.dwControlKeyState));
+                          ScanCode := Chr(RemapScanCode(Buf.KeyEvent.wVirtualScanCode, Buf.KeyEvent.dwControlKeyState,
+                                                        Buf.KeyEvent.wVirtualKeyCode));
              end
              end
             else
             else
              begin
              begin
                SpecialKey := FALSE;
                SpecialKey := FALSE;
                ScanCode := Chr(Ord(buf.KeyEvent.AsciiChar));
                ScanCode := Chr(Ord(buf.KeyEvent.AsciiChar));
              end;
              end;
-            break;
+
+                        if Buf.KeyEvent.wVirtualKeyCode in [VK_NUMPAD0..VK_NUMPAD9] then
+                         if AltKey then
+                          begin
+                            Keypressed := false;
+                            Specialkey := false;
+                            ScanCode := #0;
+                          end
+                            else BREAK;
           end;
           end;
+          end { if }
+           else if (Buf.KeyEvent.wVirtualKeyCode in [VK_MENU]) then
+                 if DoingNumChars then
+                  if DoingNumCode > 0 then
+                   begin
+                     ScanCode := Chr(DoingNumCode);
+                     Keypressed := true;
+
+                     DoingNumChars := false;
+                     DoingNumCode := 0;
+                     BREAK;
+                   end; { if }
+
       end;
       end;
    end;
    end;
 end;
 end;
@@ -583,7 +631,6 @@ begin
 end;
 end;
 
 
 
 
-
 {****************************************************************************
 {****************************************************************************
                           HighLevel Crt Functions
                           HighLevel Crt Functions
 ****************************************************************************}
 ****************************************************************************}
@@ -598,7 +645,7 @@ begin
   CharInfo.UnicodeChar := 32;
   CharInfo.UnicodeChar := 32;
   CharInfo.Attributes := TextAttr;
   CharInfo.Attributes := TextAttr;
 
 
-  Y := WinMinY + (Y - 1);
+  Y := WinMinY + Y-1;
 
 
   SrcRect.Top := Y - 01;
   SrcRect.Top := Y - 01;
   SrcRect.Left := WinMinX - 1;
   SrcRect.Left := WinMinX - 1;
@@ -727,19 +774,16 @@ begin
             Inc(CurrX);
             Inc(CurrX);
           end; { else }
           end; { else }
   end; { case }
   end; { case }
-
   if CurrX > WinMaxX then
   if CurrX > WinMaxX then
     begin
     begin
       CurrX := WinMinX;
       CurrX := WinMinX;
       Inc(CurrY);
       Inc(CurrY);
     end; { if }
     end; { if }
-
   While CurrY > WinMaxY do
   While CurrY > WinMaxY do
    begin
    begin
      RemoveLine(1);
      RemoveLine(1);
      Dec(CurrY);
      Dec(CurrY);
    end; { while }
    end; { while }
-
 end;
 end;
 
 
 
 
@@ -877,13 +921,13 @@ End;
 procedure AssignCrt(var F: Text);
 procedure AssignCrt(var F: Text);
 begin
 begin
   Assign(F,'');
   Assign(F,'');
-
   TextRec(F).OpenFunc:=@CrtOpen;
   TextRec(F).OpenFunc:=@CrtOpen;
 end;
 end;
 
 
 
 
-var CursorInfo : TConsoleCursorInfo;
-    ConsoleInfo: TConsoleScreenBufferinfo;
+var
+  CursorInfo  : TConsoleCursorInfo;
+  ConsoleInfo : TConsoleScreenBufferinfo;
 begin
 begin
   { Initialize the output handles }
   { Initialize the output handles }
   OutHandle := GetStdHandle(STD_OUTPUT_HANDLE);
   OutHandle := GetStdHandle(STD_OUTPUT_HANDLE);
@@ -902,7 +946,6 @@ begin
   CursorSaveY := ConsoleInfo.dwCursorPosition.Y;
   CursorSaveY := ConsoleInfo.dwCursorPosition.Y;
   TextAttr := ConsoleInfo.wAttributes;
   TextAttr := ConsoleInfo.wAttributes;
 
 
-
   { Load startup values }
   { Load startup values }
   ScreenWidth := GetScreenWidth;
   ScreenWidth := GetScreenWidth;
   ScreenHeight := GetScreenHeight;
   ScreenHeight := GetScreenHeight;
@@ -910,6 +953,8 @@ begin
   TurnMouseOff;
   TurnMouseOff;
 
 
   WindMax := (ScreenWidth - 1) OR ((ScreenHeight - 1) SHL 8);
   WindMax := (ScreenWidth - 1) OR ((ScreenHeight - 1) SHL 8);
+  DoingNumChars := false;
+  DoingNumCode := 0;
 
 
   { Redirect the standard output }
   { Redirect the standard output }
   AssignCrt(Output);
   AssignCrt(Output);
@@ -922,7 +967,10 @@ begin
 end. { unit Crt }
 end. { unit Crt }
 {
 {
   $Log$
   $Log$
-  Revision 1.10  1999-08-24 13:15:44  peter
+  Revision 1.11  1999-08-28 09:30:39  peter
+    * fixes from Maarten Bekers
+
+  Revision 1.10  1999/08/24 13:15:44  peter
     * Removeline fixed
     * Removeline fixed
 
 
   Revision 1.9  1999/07/06 22:44:11  florian
   Revision 1.9  1999/07/06 22:44:11  florian