title: Delphi VirtualKey to WideString/UNICODE using TNT controls on non-unicode Delphi 7
body: <p>I am using this code to convert a virtual key to WideString:</p>
  <pre><code>function VKeytoWideString (Key : Word) : WideString; 
  var 
   WBuff         : array [0..255] of WideChar; 
   KeyboardState : TKeyboardState; 
   UResult       : Integer;
  begin 
   Result := '';
   GetKeyBoardState (KeyboardState); 
   ZeroMemory(@WBuff[0], SizeOf(WBuff));
   UResult := ToUnicode(key, MapVirtualKey(key, 0), KeyboardState, WBuff, Length(WBuff), 0); 
   if UResult &gt; 0 then
    SetString(Result, WBuff, UResult)
   else if UResult = -1 then
    Result := WBuff;
  end; 
  </code></pre>
  <p>It works fine on my PC, but on a Chinese PC I get this:</p>
  <p><a href="https://i.stack.imgur.com/nsn2j.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nsn2j.png" alt="foo" /></a></p>
  
  <p>It converts the Chinese chars to Hanyu Pinyin. I think the function actually returns the <strong>raw input</strong> of the keyboard and not what the user actually wants to type in.</p>
  <p>How should I handle this?</p>