标题:我应该如何用代码直接切换到默认输入法中的“英文输入”呢?谢谢!
只看楼主
mansohu
Rank: 1
等 级:新手上路
帖 子:190
专家分:0
注 册:2013-3-20
结帖率:21.05%
 问题点数:0 回复次数:3 
我应该如何用代码直接切换到默认输入法中的“英文输入”呢?谢谢!
我的系统里的默认输入法是 《微软拼音简捷》(而不是英文法输入法),用 ImmIsIME 检测的结果:它也是中文输入法(和其它输入法类似,它也要用“Shift”切换中英文)。请问如果我不了解各种输入法的快捷键使用,也不了解系统里都有哪些输入法,我应该如何用代码直接切换到默认输入法中的“英文输入”呢?谢谢!
搜索更多相关主题的帖子: 英文输入 如何 快捷键 微软拼音 中文输入法 
2015-02-17 13:10
mansohu
Rank: 1
等 级:新手上路
帖 子:190
专家分:0
注 册:2013-3-20
得分:0 
还请各位老师指导!谢谢!
2015-02-25 10:42
xzlxzlxzl
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:湖北
等 级:贵宾
威 望:125
帖 子:1091
专家分:5825
注 册:2014-5-3
得分:0 
要修改系统默认输入法为英文,首先系统得安装有英文输入法(一般为“简体中文-美式键盘”输入法),然后通过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

输入法.rar (2.34 KB)


[ 本帖最后由 xzlxzlxzl 于 2015-2-25 21:06 编辑 ]
2015-02-25 21:00
yangfrancis
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:贵宾
威 望:141
帖 子:1510
专家分:7661
注 册:2014-5-19
得分:0 
弱弱地问一句,那四个API函数各自的具体功能是什么啊?光看代码有点看不出来。望版主解释一二。谢谢。
2015-02-26 21:59



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-442080-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.247506 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved