Browse Source

* Win32 kbd input unicode translation via MultiByteToWideChar

git-svn-id: trunk@16144 -
nickysn 15 years ago
parent
commit
d22d5be5c7
1 changed files with 11 additions and 13 deletions
  1. 11 13
      packages/ptc/src/win32/base/kbd.inc

+ 11 - 13
packages/ptc/src/win32/base/kbd.inc

@@ -78,7 +78,8 @@ var
   AsciiBuf: Word;
   press: Boolean;
   uni: Integer;
-  tmp: Integer;
+  TranslatedCharacters, TranslatedWideCharacters: Integer;
+  WideStr: WideString;
   KeyCode: Integer;
 begin
   Result := 0;
@@ -117,21 +118,18 @@ begin
     begin
       scancode := (lParam shr 16) and $FF;
       {todo: ToUnicode (Windows NT)}
-      tmp := ToAscii(wParam, scancode, @KeyStateArray, @AsciiBuf, 0);
-      if (tmp = 1) or (tmp = 2) then
+      TranslatedCharacters := ToAscii(wParam, scancode, @KeyStateArray, @AsciiBuf, 0);
+      if (TranslatedCharacters = 1) or (TranslatedCharacters = 2) then
       begin
-        if tmp = 2 then
+        TranslatedWideCharacters := MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, @AsciiBuf, TranslatedCharacters, nil, 0);
+        if TranslatedWideCharacters <> 0 then
         begin
-//          Writeln('[', AsciiBuf, ']'); {???? todo: dead keys ????}
-        end
-        else
-        begin
-//          Write(Chr(AsciiBuf));
-          {todo: codepage -> unicode}
-          if (AsciiBuf and $FF) <= 126 then
-            uni := AsciiBuf and $FF;
-        end;
+          SetLength(WideStr, TranslatedWideCharacters);
+          MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, @AsciiBuf, TranslatedCharacters, @WideStr[1], TranslatedWideCharacters);
 
+          if Length(WideStr) = 1 then
+            uni := Ord(WideStr[1]);
+        end;
       end;
     end;