I would like to convert a virtual key to a WideString.
That’s what I have so far…
function VKeytoWideString (Key : Word) : WideString;
var
WBuff : array [0..255] of WideChar;
KeyboardState : TKeyboardState;
UResult : Integer;
begin
GetKeyBoardState (KeyboardState);
UResult := ToUnicode(key, MapVirtualKey(key, 0), KeyboardState, WBuff, 0,0);
Result := WBuff;
case UResult of
0 : Result := '';
1 : SetLength (Result, 1);
2 :;
else
Result := '';
end;
end;
it always returns 0 but why?
Please help.
You are setting the
cchBuffparameter ofToUnicode()to 0 instead of the actual buffer size, so the function cannot store any characters it translates.Try this instead: