惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
Netflix TechBlog - Medium
G
Google Developers Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
The Blog of Author Tim Ferriss
Microsoft Azure Blog
Microsoft Azure Blog
GbyAI
GbyAI
L
LangChain Blog
云风的 BLOG
云风的 BLOG
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
aimingoo的专栏
aimingoo的专栏
P
Proofpoint News Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
小众软件
小众软件
WordPress大学
WordPress大学
A
About on SuperTechFans
大猫的无限游戏
大猫的无限游戏
C
Check Point Blog
月光博客
月光博客
Stack Overflow Blog
Stack Overflow Blog
美团技术团队
Jina AI
Jina AI
T
Tailwind CSS Blog
Google DeepMind News
Google DeepMind News
D
Docker

博客园 - shappy

5.12默哀 台风 - shappy - 博客园 童谣 回家 Web Control中填写JavaScript报告"缺少对象"错误问题解决 Midas如何在服务器端自动产生流水号 Clientdataset关于record change by another user错误的总结 游凤凰 设定MSAgent的说话(Balloon)停留时间 获取Agent角色的动作列表 MSAgent简介 摘录 DelphiX简介 摘录 DelphiX的刷新 TList源码分析 摘录 几种文字编码的介绍 汉字编码标准与识别 摘录 Tclientdataset实现反向排序 关于Tclientdataset的bug 队列类
获取/打开/关闭输入法
shappy · 2007-05-14 · via 博客园 - shappy

//必须注意一点,也是很重要的,程序退出前请执行关闭输入法,否则程序会花很长时间才能关闭-影响到其他所有程序和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.