要修改系统默认输入法为英文,首先系统得安装有英文输入法(一般为“简体中文-美式键盘”输入法),然后通过api函数SystemParametersInfo更换系统默认的输入法,下述代码已经能随心所欲切换输入法并更改系统默认的输入法了。
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 GetKeyboardLayoutList Lib "user32" (ByVal nBuff As Long, lpList As Long) As Long
Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByRef lpvParam As Any, ByVal fuWinIni 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 Sub Command1_Click()
Dim i As Long, j As Long, hk(30) As Long
'强行切换为中文,如有需要还可以指定哪一种中文输入如:五笔、搜狗、智能ABC等
j = GetKeyboardLayoutList(30, hk(0))
For i = 0 To j - 1
If ImmIsIME(hk(i)) = 1 Then
ActivateKeyboardLayout hk(i), 0
'强制切换为中文输入法
Exit For
End If
Next
Text1.SetFocus
End Sub
Private Sub Command2_Click()
Dim i As Long, j As Long, hk(30) As Long
'强行切换为英文
j = GetKeyboardLayoutList(30, hk(0))
For i = 0 To j - 1
If ImmIsIME(hk(i)) = 0 Then
ActivateKeyboardLayout hk(i), 0
'强制切换为英文输入法
Exit For
End If
Next
Text1.SetFocus
End Sub
Private Sub Form_Load()
Dim i As Long, j As Long, hk(30) As Long, b As String * 100, k As Integer, a As String, m As Long
'显示当前系统安装的所有输入法
j = GetKeyboardLayoutList(30, hk(0))
SystemParametersInfo 89, 0, m, 0 '获取默认输入法
List1.Clear
For i = 0 To j - 1
ImmGetDescription hk(i), b, 100
k = InStr(b, Chr(0)) - 1
If k > 0 Then
a = Left(b, k)
Else
a = "简体中文-美式键盘"
End If
If m = hk(i) Then a = a & "
系统默认输入法"
List1.AddItem a
Next
End Sub
Private Sub List1_DblClick()
Dim i As Long, j As Long, hk(30) As Long, f As Boolean
'SystemParametersInfo 89, 0, j, 0获取默认输入法
j = GetKeyboardLayoutList(30, hk(0))
ActivateKeyboardLayout hk(List1.ListIndex), 0
'强制切换为英文输入法
f = SystemParametersInfo(90, 0, hk(List1.ListIndex), 0)
'同时将默认输入法改为简体中文-美式键盘
Form_Load
Text1.SetFocus
End Sub
[
本帖最后由 xzlxzlxzl 于 2015-2-25 21:06 编辑 ]