In Windows we can use the "Ctrl+shift" key to call in or toggle the Chinese input method, but doing so each time is to make the input method at the top of the IME list first called. Usually we have to press several times in a row "ctrl+shift" to the habit of the input method. I developed a small program, through which you can put any input method at the top of the Input method list.
Its principle is: Use the Loadkeyboardlayout function can change the order of input method, as long as in the first parameter pass the target input method of Keyboardlayoutname, the second parameter with Klf_reorder on it.
For example, AA = Loadkeyboardlayout (″00000409″, Klf_reorder) makes English the first. So how do you get keyboardlayoutname? Because using Getkeyboardlayoutname can return the keyboardlayoutname of the current input method, we can use the Getkeyboardlayoutlist function to get all the input methods first. Then use the Activatekeyboardlayout () function to set the current input method, and finally you can get its keyboardlayoutname. The specific steps are as follows:
After opening VB to select the Standard EXE document, add a ComboBox and a command control on the FORM1, enter the following program.
The following API functions are used for input method operation
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 as Long, bufflen as Long
Private Buff as String
Private Retstr as String
Private Retcount as Long
Private Kln as String
Private Sub Command1_Click ()
If Combo1.listindex =-1 then′ If the user has not selected an input method, an error message is displayed
Msgbox″ Please select an input method first ″
Exit Sub
End If
Change input Order
KLN = String (8, 0)
Activatekeyboardlayout hkb (Combo1.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) to obtain the current input method
Noofkbdlayout = getkeyboardlayoutlist (hkb (0)) to obtain all input methods
′redim layoutlist (noofkbdlayout) as String
For i = 1 to Noofkbdlayout
If Immisime (HKB (i-1)) = 1 then′ Chinese Input method
Bufflen = 255
Retcount = Immgetdescription (HKB (i-1), Buff, Bufflen)
Retstr = Left (Buff, Retcount)
Combo1.additem Retstr
Else
Retstr =″english (American) ″′ English Input method
Combo1.additem Retstr
End If
Next
Activatekeyboardlayout hcurkbdlayout, 0′ Restore the original Input method
End Sub
After running, select the target input method in ComboBox and press command.