VB and input method

xiaoxiao2021-03-06  18

Use the VB plus API to easily adjust the order of the input method and set the current input method, each input method corresponds to a keyboard layout, so you can use the getKey-BoardLayout function to get it, you can set it with ActivateKeyboardLayout. With loadKeyboardLayout, you can change the order of the input method, set the second parameter of the function to KLF_REORDER, you can set the input method to the first bit. The debug code is posted below

'API declaration

Private Declare Function GetKeyboardLayoutList Lib "User32" (Byval NBuff As Long, LPLIST AS Long

Private Declare Function Immgetdescription LIB "Imm32.dll" Alias ​​"Immgetdescriptiona" (Byval HKL AS String, Byval Ubufflen As Long) As long

Private Declare Function Immisime LIB "IMM32.DLL" (Byval HKL As Long) As Long

Private Declare Function ActivateKeyboardLayout Lib "User 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 flow_load ()

BUFF = String (255, 0)

Hcurkbdlayout = getKeyboardLayout (0) 'gets the current input method

NOOFKBDLAYOUT = GetKeyboardLayoutList (25, HKB (0)) 'gets all input method

For i = 1 to noofBDLAYOUT

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 'Restores the original input method

End Sub

Private submmand1_click ()

If Combo1.listIndex = -1 Then 'If the user has not selected the input method, display the error message

Msgbox "Please select an input method first"

EXIT SUB

END IF

'Change the order of input

Kln = String (8, 0)

ActivateKeyboardLayout HKB (Combo1.ListIndex), 0 'Sets the current input method

'The following code is the order of adjusting the input method. Mask the following code can achieve switching

Res = getKeyboardLayoutName (kln) 'Get the keyboard layout of the current input method

Res = loadingKeyboardLayout (KLN, KLF_REORDER) 'Adjusting the input method sequence

ActivateKeyboardLayout Hcurkbdlayout, 0 'Restore input method

End Sub

'The above code refers to the post on 9CBS, adds yourself to explain and understand

转载请注明原文地址:https://www.9cbs.com/read-42383.html

New Post(0)