用vb加api可以輕鬆的調整輸入法的順序和設定當前輸入法,每種輸入法都對應有個鍵盤布局,所以就可以用getkey- boardlayout函式得到,用activatekeyboardlayout就可以設定了。用loadkeyboardlayout就可以改變輸入法的順序了,將該函式的第二個引數設定為klf_reorder,就可以把該輸入法設定為第一位。下面貼出除錯過的**
'api宣告
private declare function getkeyboardlayoutlist lib "user32" (byval nbuff as long, lplist as long) as long
private declare function immgetdescription lib "imm32.dll" alias "immgetdescriptiona" (byval hkl as long, byval lpsz as string, byval ubuflen as long) as long
private declare function immisime lib "imm32.dll" (byval hkl as long) as long
private declare function activatekeyboardlayout lib "user32" (byval hkl as long, byval flags as long) as long
private declare function getkeyboardlayout lib "user32" (byval dwlayout as long) as long
private declare function getkeyboardlayoutname lib "user32" alias "getkeyboardlayoutnamea" (byval pwszklid as string) as long
private declare function loadkeyboardlayout lib "user32" alias "loadkeyboardlayouta" (byval pwszklid as string, byval flags as long) as long
const klf_reorder = &h8
private noofkbdlayout as long, i as long, j as long
private hkb(24) as long, bufflen as long
private buff as string
private retstr as string
private retcount as long
private kln as string
private hcurkbdlayout
private sub form_load()
buff = string(255, 0)
hcurkbdlayout = getkeyboardlayout(0) '取得目前的輸入法
noofkbdlayout = getkeyboardlayoutlist(25, hkb(0)) '取得所有輸入法
for i = 1 to noofkbdlayout
if immisime(hkb(i - 1)) = 1 then '中文輸入法
bufflen = 255
retcount = immgetdescription(hkb(i - 1), buff, bufflen)
retstr = left(buff, retcount)
***bo1.additem retstr
else
retstr = "english (american)" '英文輸入法
***bo1.additem retstr
end if
next
activatekeyboardlayout hcurkbdlayout, 0 '恢復原來的輸入法
end sub
private sub ***mand1_click()
if ***bo1.listindex = -1 then '如果使用者尚未選擇輸入法,顯示出錯資訊
msgbox "請先選擇乙個輸入法"
exit sub
end if
'改變輸入法順序
kln = string(8, 0)
activatekeyboardlayout hkb(***bo1.listindex), 0 '設定當前輸入法
'下面的**是調整輸入法的順序。遮蔽掉下面的**就可以實現輸入法的切換
res = getkeyboardlayoutname(kln) '得到當前輸入法的鍵盤布局
res = loadkeyboardlayout(kln, klf_reorder) '將輸入法順序調整
activatekeyboardlayout hcurkbdlayout, 0 '還原輸入法
end sub
'以上**參考了csdn上的帖子,自己加了注釋以便說明和理解
開啟和關閉輸入法
procedure closeedtime edt tedit varkeystates tkeyboardstate begin getkeyboardstate keystates if keystates vk capital 1 then begin setcapslockkey vk ca...
開啟和關閉輸入法
在應用程式中,我們經常需要控制edittext的輸入法開啟與關閉,手指touch之後,自動開啟了輸入法,可是怎麼控制關閉輸入法,除了輸入法自己的關閉按鈕之外,還有以下的方法。一 開啟輸入法視窗 inputmethodmanager inputmethodmanager inputmethodmana...
輸入法控制
unit u ime inte ce implementation uses windows,forms,imm,sysutils,messages varstmpclassname,stmpime string 失去焦點時的控制項名稱和輸入法名稱 msghandle hhook 0 判斷當前類名是...