Posted on Leave a comment

Delphi keyboard

function GetRealChar(AKey: Word): Char;
var
  Layout: HKL;
  KeyboardState: TKeyboardState;
  RealCode: AnsiString;
  ScanCode: Integer;
  s: string;
begin
  Layout := GetKeyboardLayout(GetCurrentThreadID);
  SetLength(RealCode, 1);
  FillChar(RealCode[1], Length(RealCode), 0);
  FillChar(KeyboardState[0], SizeOf(KeyboardState), 0);
  KeyboardState[AKey] := 0;
  ScanCode := (AKey shr 16) and $FF;
  ToAsciiEx(AKey, ScanCode, KeyboardState, PChar(RealCode), 0, Layout);
  s := RealCode;
  Result := s[1];
end;
Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.