声明 API 函数: function boolean ImmSimulateHotKey (ULong hWnd, ULong dwHotKeyID) library "IMM32.dll" function ulong GetKeyboardLayout(ulong d" name="description" />

如何在程序中自动控制切换中英文输入法?

发表于:2007-05-25来源:作者:点击数: 标签:程序自动控制切换何在中英文
MI LY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">声明 API 函数: function boolean ImmSimulateHotKey (ULong hWnd, ULong dwHotKeyID) library "IMM32.dll" function ulong GetKeyboardLayout(ulong d

MILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">声明API函数:

function boolean ImmSimulateHotKey (ULong hWnd, ULong dwHotKeyID) library "IMM32.dll"

function ulong GetKeyboardLayout(ulong dwLayout) LIBRARY "user32.dll"

function boolean ImmIsIME(uLong hklKeyboardLayout) library "IMM32.DLL"

定义变量:

constant int IME_THotKey_IME_NonIME_Toggle=112

ulong hklCurrent

ulong hnd

切换到英文输入法:

hklCurrent=GetKeyboardLayout(0)

if ImmIsIME(hklCurrent) then

   hnd=Handle(parent)

   ImmSimulateHotKey(hnd,IME_THotKey_IME_NonIME_Toggle)

end if

切换到中文输入法:

hklCurrent=GetKeyboardLayout(0)

if not ImmIsIME(hklCurrent) then

  hnd=Handle(parent)

  ImmSimulateHotKey(hnd,IME_THotKey_IME_NonIME_Toggle)

end if

可根据需要,触发两段不同的脚本以达到动态切换中英文输入法的目的

原文转自:http://www.ltesting.net