向指定HWND发送字符串

 
  1. procedure SendKeys(focushld: hwnd; sSend: string);
  2. var
  3.   i: integer;
  4.   ch: byte;
  5. begin
  6.   if focushld = 0 then Exit;
  7.   i := 1;
  8.   while i <= Length(sSend) do
  9.   begin
  10.     ch := byte(sSend[i]);
  11.     if Windows.IsDBCSLeadByte(ch) then
  12.     begin
  13.       Inc(i);
  14.       SendMessage(focushld, WM_IME_CHAR, MakeWord(byte(sSend[i]), ch), 0);
  15.     end
  16.     else
  17.       SendMessage(focushld, WM_IME_CHAR, word(ch), 0);
  18.     Inc(i);
  19.   end;
  20.   postmessage(focushld, WM_keydown, 130); //按回车键
  21. end;
原文地址:https://www.cnblogs.com/zhaoshujie/p/9594831.html