参考一下我的,你可以更灵活地调用输入法: var Form1: TForm1; ImmHkl:array[0..20] of HKL; ImmName:array[0..50] of Char; implementation {$R *.DFM} procedure TForm1.FormCreate(Sender: TObject); var i:Integer; begin for i:=0 to GetKeyboardLayoutList(sizeof(ImmHkl),ImmHkl)-1 do begin if ImmIsIME(ImmHkl[i]) then begin ImmGetDescription(ImmHkl[i],ImmName,sizeof(ImmName)); ComboBox1.Items.Add(ImmName); end else ComboBox1.Items.Add('English'); end; end;procedure TForm1.ComboBox1Click(Sender: TObject); begin ActivateKeyboardLayout(ImmHkl[ComboBox1.ItemIndex],0); GetKeyboardLayoutName(ImmName); LoadKeyboardLayout(ImmName,KLF_ACTIVATE); Memo1.SetFocus; end; end.
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Keyboard Layouts
你会发现规律的:)
然后设个全局变量保存用户选择的输入法,在要输入中文的地方imename都用变量来赋值,就可以避免用户使用软件时,频频转换输入法。
var
Form1: TForm1;
ImmHkl:array[0..20] of HKL;
ImmName:array[0..50] of Char;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
var
i:Integer;
begin
for i:=0 to GetKeyboardLayoutList(sizeof(ImmHkl),ImmHkl)-1 do
begin
if ImmIsIME(ImmHkl[i]) then
begin
ImmGetDescription(ImmHkl[i],ImmName,sizeof(ImmName));
ComboBox1.Items.Add(ImmName);
end
else
ComboBox1.Items.Add('English');
end;
end;procedure TForm1.ComboBox1Click(Sender: TObject);
begin
ActivateKeyboardLayout(ImmHkl[ComboBox1.ItemIndex],0);
GetKeyboardLayoutName(ImmName);
LoadKeyboardLayout(ImmName,KLF_ACTIVATE);
Memo1.SetFocus;
end;
end.