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

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
Help Net Security
Help Net Security
P
Privacy International News Feed
T
Threat Research - Cisco Blogs
C
Cisco Blogs
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
L
LINUX DO - 热门话题
Security Latest
Security Latest
A
Arctic Wolf
G
GRAHAM CLULEY
月光博客
月光博客
S
Securelist
D
Docker
J
Java Code Geeks
T
Troy Hunt's Blog
T
Tenable Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
SecWiki News
SecWiki News
S
Security @ Cisco Blogs
量子位
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
L
LINUX DO - 最新话题
Recent Commits to openclaw:main
Recent Commits to openclaw:main
aimingoo的专栏
aimingoo的专栏
博客园 - 【当耐特】
H
Heimdal Security Blog
The Hacker News
The Hacker News
博客园 - 三生石上(FineUI控件)
Application and Cybersecurity Blog
Application and Cybersecurity Blog
N
Netflix TechBlog - Medium
Vercel News
Vercel News
Forbes - Security
Forbes - Security
B
Blog RSS Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
IT之家
IT之家
B
Blog
MongoDB | Blog
MongoDB | Blog
博客园 - 聂微东
Google DeepMind News
Google DeepMind News
S
Secure Thoughts
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Check Point Blog
云风的 BLOG
云风的 BLOG
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
The Blog of Author Tim Ferriss
L
Lohrmann on Cybersecurity
F
Full Disclosure
D
Darknet – Hacking Tools, Hacker News & Cyber Security
P
Proofpoint News Feed

博客园 - 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.