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
2 changed files with 16 additions and 7 deletions
  1. 15 6
      packages/rtl-console/src/win/keyboard.pp
  2. 1 1
      packages/rtl-console/src/win/winevent.pp

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

@@ -228,7 +228,7 @@ begin
                      begin                          {add to queue}
                        fillchar (ir, sizeof (ir), 0);
                        bKeyDown := true;
-                       AsciiChar := char (c);
+                       UnicodeChar := WideChar (c);
                                                 {and add to queue}
                        EnterCriticalSection (lockVar);
                        keyboardeventqueue[nextfreekeyevent]:=ir.Event.KeyEvent;
@@ -641,6 +641,15 @@ CONST
    (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;
 var key : TKeyEvent;
     ss  : byte;
@@ -652,16 +661,16 @@ begin
   Key := 0;
   if t.bKeyDown then
   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 }
-    if t.AsciiChar <> #0 then
+    if t.UnicodeChar <> WideChar(0) then
     begin
       if (t.dwControlKeyState and ENHANCED_KEY <> 0) and
          (t.wVirtualKeyCode = $DF) then
         begin
           t.dwControlKeyState:=t.dwControlKeyState and not ENHANCED_KEY;
           t.wVirtualKeyCode:=VK_DIVIDE;
-          t.AsciiChar:='/';
+          t.UnicodeChar:='/';
         end;
       {drivers needs scancode, we return it here as under dos and linux
        with $03000000 = the lowest two bytes is the physical representation}
@@ -669,13 +678,13 @@ begin
       Scancode:=KeyToQwertyScan[t.wVirtualKeyCode AND $00FF];
       If ScanCode>0 then
         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);
       key := key or (ss shl 16);
       if (ss and kbAlt <> 0) and rightistruealt(t.dwControlKeyState) then
         key := key and $FFFFFF00;
 {$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}
     end else
     begin

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

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