Browse Source

* switch to using ReadConsoleInputW instead of ReadConsoleInputA in the windows
keyboard unit. This way the console input is read using Unicode and is later
translated to the OEM character set via WideCharToMultiByte. This is will
allow returning Unicode character codes once enhanced key events are
implemented.

git-svn-id: branches/unicodekvm@40232 -

nickysn 6 years ago
parent
commit
28235033d7

+ 15 - 6
packages/rtl-console/src/win/keyboard.pp

@@ -228,7 +228,7 @@ begin
                      begin                          {add to queue}
                      begin                          {add to queue}
                        fillchar (ir, sizeof (ir), 0);
                        fillchar (ir, sizeof (ir), 0);
                        bKeyDown := true;
                        bKeyDown := true;
-                       AsciiChar := char (c);
+                       UnicodeChar := WideChar (c);
                                                 {and add to queue}
                                                 {and add to queue}
                        EnterCriticalSection (lockVar);
                        EnterCriticalSection (lockVar);
                        keyboardeventqueue[nextfreekeyevent]:=ir.Event.KeyEvent;
                        keyboardeventqueue[nextfreekeyevent]:=ir.Event.KeyEvent;
@@ -641,6 +641,15 @@ CONST
    (n : $00; s : $0F; c : $94; a: $00));     {0F Tab }
    (n : $00; s : $0F; c : $94; a: $00));     {0F Tab }
 
 
 
 
+function WideCharToOemCpChar(WC: WideChar): Char;
+var
+  Res: Char;
+begin
+  if WideCharToMultiByte(CP_OEMCP,0,@WC,1,@Res,1,nil,nil)=0 then
+    Res:=#0;
+  WideCharToOemCpChar:=Res;
+end;
+
 function TranslateKey (t : TKeyEventRecord) : TKeyEvent;
 function TranslateKey (t : TKeyEventRecord) : TKeyEvent;
 var key : TKeyEvent;
 var key : TKeyEvent;
     ss  : byte;
     ss  : byte;
@@ -652,16 +661,16 @@ begin
   Key := 0;
   Key := 0;
   if t.bKeyDown then
   if t.bKeyDown then
   begin
   begin
-    { ascii-char is <> 0 if not a specal key }
+    { unicode-char is <> 0 if not a specal key }
     { we return it here otherwise we have to translate more later }
     { we return it here otherwise we have to translate more later }
-    if t.AsciiChar <> #0 then
+    if t.UnicodeChar <> WideChar(0) then
     begin
     begin
       if (t.dwControlKeyState and ENHANCED_KEY <> 0) and
       if (t.dwControlKeyState and ENHANCED_KEY <> 0) and
          (t.wVirtualKeyCode = $DF) then
          (t.wVirtualKeyCode = $DF) then
         begin
         begin
           t.dwControlKeyState:=t.dwControlKeyState and not ENHANCED_KEY;
           t.dwControlKeyState:=t.dwControlKeyState and not ENHANCED_KEY;
           t.wVirtualKeyCode:=VK_DIVIDE;
           t.wVirtualKeyCode:=VK_DIVIDE;
-          t.AsciiChar:='/';
+          t.UnicodeChar:='/';
         end;
         end;
       {drivers needs scancode, we return it here as under dos and linux
       {drivers needs scancode, we return it here as under dos and linux
        with $03000000 = the lowest two bytes is the physical representation}
        with $03000000 = the lowest two bytes is the physical representation}
@@ -669,13 +678,13 @@ begin
       Scancode:=KeyToQwertyScan[t.wVirtualKeyCode AND $00FF];
       Scancode:=KeyToQwertyScan[t.wVirtualKeyCode AND $00FF];
       If ScanCode>0 then
       If ScanCode>0 then
         t.wVirtualScanCode:=ScanCode;
         t.wVirtualScanCode:=ScanCode;
-      Key := byte (t.AsciiChar) + (t.wVirtualScanCode shl 8) + $03000000;
+      Key := byte (WideCharToOemCpChar(t.UnicodeChar)) + (t.wVirtualScanCode shl 8) + $03000000;
       ss := transShiftState (t.dwControlKeyState);
       ss := transShiftState (t.dwControlKeyState);
       key := key or (ss shl 16);
       key := key or (ss shl 16);
       if (ss and kbAlt <> 0) and rightistruealt(t.dwControlKeyState) then
       if (ss and kbAlt <> 0) and rightistruealt(t.dwControlKeyState) then
         key := key and $FFFFFF00;
         key := key and $FFFFFF00;
 {$else not USEKEYCODES}
 {$else not USEKEYCODES}
-      Key := byte (t.AsciiChar) + ((t.wVirtualScanCode AND $00FF) shl 8) + $03000000;
+      Key := byte (WideCharToOemCpChar(t.UnicodeChar)) + ((t.wVirtualScanCode AND $00FF) shl 8) + $03000000;
 {$endif not USEKEYCODES}
 {$endif not USEKEYCODES}
     end else
     end else
     begin
     begin

+ 1 - 1
packages/rtl-console/src/win/winevent.pp

@@ -122,7 +122,7 @@ interface
               }
               }
               if not(ExitEventHandleThread) then
               if not(ExitEventHandleThread) then
                 begin
                 begin
-                   if ReadConsoleInput(StdInputHandle,ir[0],irsize,dwRead) then
+                   if ReadConsoleInputW(StdInputHandle,ir[0],irsize,dwRead) then
                     begin
                     begin
                       i:=0;
                       i:=0;
                       EnterCriticalSection(HandlerChanging);
                       EnterCriticalSection(HandlerChanging);