VisualBasic内嵌汇编语言解决方案
在Windows中,我们可以使用“Ctrl+Shift”键调入或切换中文输入法,但这样做总是会使输入法列表顶部的输入法先被调用。平时要连续按几次“Ctrl+Shift”才能调出习惯输入法。我编了一个小程序,通过它我可以把任何输入法放在输入法列表的最前面。
它的原理是使用LoadKeyboardLayout函数可以改变输入法的顺序,只要在第一个参数中传递目标输入法的KeyboardlayoutName,在第二个参数中使用KLF _重排序即可。
比如AA = LoadKeyboardLayout ("0000409 ",KLF _ Reorder)让英文第一。那怎么得到KeyboardlayoutName呢?因为GetKeyboardLayoutname可以返回当前输入法的KeyboardLayoutname,所以我们可以使用GetKeyboardLayoutList函数先获取所有输入法,然后用activateKeyboardlayout()函数设置当前输入法,最后获取其KeyboardlayoutName。具体步骤如下:
打开VB后,选择标准的EXE文档,在Form1上添加Combobox和command控件,进入下面的程序。
以下API函数用于输入法操作
私有声明函数getkeyboardlayout Lib " user 32 " _
(ByVal nbuff As Long,lpList As Long
私有声明函数immget description Lib " imm32 . dll "_
Alias " immget description a "( ByVal hkl As Long,_
ByVal lpsz As String, ByVal uBufLen As Long )
私有声明函数ImmIsIME Lib " imm32 . dll "( ByVal hkl As Long )
私有声明函数ActivateKeyboardLayout Lib " user 32 "_
(ByVal hkl As Long, ByVal标志为Long)Long
私有声明函数GetKeyboardLayout Lib " user 32 "( ByVal dw layout为Long)Long
私有声明函数GetKeyboardLayoutName Lib " user 32 " Alias _
" GetKeyboardLayoutName a "( ByVal pwszKLID为String)Long
私有声明函数LoadKeyboardLayout Lib " user 32 " Alias " LoadKeyboardLayoutA "_
(ByVal pwszsz BuffLen As Long
Private Buff As String
Private RetStr As String
Private RetCount As String
private command 1 _ click()
If combo 1 . listindex =-1 then '如果用户没有选择输入法,错误消息
msgbox“请先选择一种输入法”
exit sub
end if
'更改输入法顺序
kln = String(8,0)
ActivateKeyboardLayout hKB(combo 1 .ListIndex),0
RES = GetKeyboardLayoutName(kln)
RES = LoadKeyboardLayout(kln,KLF _ REORDER)
ActivateKeyboardLayout hCurKBDLayout,0
End Sub
private Sub Form _ Load()
Buff = String(255,0)
hcurkbdlayout = getkeyboardlayout(0)' Get当前输入法
noofbdlayout = getkeyboardlayout(25,HKB(0))' Get all input methods
' Redim Layout List(nookbdlayout)as String
for I = 1 to nookbdlayout
if immisme(HKB(I-1))= 1然后additem Retstr
Else
Retstr = " English(American)" '英文输入法
Combo1。additem Retstr
End
next
activate keyboard layout,0 '恢复原来的输入法
End Sub
0条评论