给你两个函数.SetmyIme用于设置,ResetIme用于恢复.
procedure SetmyIme(ImeName:string);
var
I: Integer;
HandleToSet: HKL;
begin
if not SysLocale.FarEast then Exit;
if ImeName <> '' then
begin
if (AnsiCompareText(ImeName, Screen.DefaultIme) <> 0)
and (Screen.Imes.Count <> 0) then
begin
HandleToSet := Screen.DefaultKbLayout;
I := Screen.Imes.IndexOf(ImeName);
if I >= 0 then
HandleToSet := HKL(Screen.Imes.Objects);
ActivateKeyboardLayout(HandleToSet, KLF_ACTIVATE);
end;
end;
end;
procedure ResetmyIme(ImeName:string);
begin
if not SysLocale.FarEast then Exit;
if ImeName <> '' then
begin
if AnsiCompareText(ImeName, Screen.DefaultIme) <> 0 then
ActivateKeyboardLayout(Screen.DefaultKbLayout, KLF_ACTIVATE);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
SetmyIme('微软拼音输入法');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ResetmyIme('微软拼音输入法');
end;
另外:关于你的向某个窗口字符,只需向改窗口连续发WM_KeyPress消息即可.