获取/打开/关闭输入法
//必须注意一点,也是很重要的,程序退出前请执行关闭输入法,否则程序会花很长时间才能关闭-影响到其他所有程序和explorer
unit IME;
interface
uses
classes, Forms,Windows, sysUtils, IMM;
function getIME():TStringList;
function GetImeFileName: string;
procedure OpenIMECN();
procedure openIME(IMEName:string);overload;
procedure openIME(myhkl:hkl);overload;
procedure closeIME();
procedure QuanJiao();
procedure CBiaoDian();
implementation
function getIME():TStringList;
var
sl:TStringList;
j:integer;
begin
sl:=TStringList.Create;
for j:=0 to screen.imes.count-1 do
begin
sl.Add(screen.Imes.strings[j]);
end;
result:=sl;
end;
function GetImeFileName: string;
var
szImeFileName: array[0..MAX_PATH] of char;
begin
if ImmGetIMEFileName(GetKeyboardLayout(0), szImeFileName, MAX_PATH) <> 0 then
Result := AnsiUpperCase(StrPas(szImeFileName))
else
Result := '';
end;
procedure OpenIME(IMEName:string);
var
I:integer;
myhkl:hkl;
begin
if ImeName<>'' then begin
if Screen.Imes.Count<>0 then begin
I:=screen.Imes.indexof(imename);
if I>=0 then begin
myhkl:=GetKeyboardLayout(0);
if not ImmIsIME(myhkl) then begin
OpenIMECN;
Application.ProcessMessages; //wait for the msg to be processed,or it wont work;
end;
myhkl:=hkl(screen.Imes.objects[i]);
activatekeyboardlayout(myhkl,KLF_ACTIVATE);//set ime
end;
end;
end;
end;
procedure openIME(myhkl:hkl);
var
_hkl:hkl;
begin
_hkl:=GetKeyboardLayout(0);
if not ImmIsIME(_hkl) then begin
OpenIMECN;
Application.ProcessMessages; //wait for the msg to be processed,or it wont work;
end;
activatekeyboardlayout(myhkl,KLF_ACTIVATE);//set ime
end;
procedure OpenIMECN();
var
_LanguageID:integer;
begin
_LanguageID:=GetSystemDefaultLangID;
if _LanguageID = ((SUBLANG_CHINESE_SIMPLIFIED shl 10) or LANG_CHINESE) then
immsimulateHotkey(Application.Handle,IME_CHOTKEY_IME_NONIME_TOGGLE)
else
immsimulateHotkey(Application.Handle,IME_THOTKEY_IME_NONIME_TOGGLE);
end;
procedure closeIME();
var
myhkl:hkl;
begin
myhkl:=GetKeyBoardLayOut(0);
if ImmIsIME(myhkl) then
immsimulateHotkey(Application.Handle,IME_CHotKey_IME_NonIME_Toggle);
end;
procedure QuanJiao();
begin
immsimulateHotkey(Application.Handle,IME_CHotKey_shape_Toggle);//È«½Ç°ë½ÇÇл»
end;
procedure CBiaoDian();
begin
immsimulateHotkey(Application.Handle,IME_CHotKey_symbol_Toggle);//ÖÐÓ¢ÎıêµãÇл»
end;
end.