如何用api判断输入法是五笔输入法还是拼音输入法?

Jeffery0211 2004-12-08 06:03:20
请教各位:如何用api判断输入法是五笔输入法还是拼音输入法?谢谢!
...全文
381 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhangjie1234 2004-12-10
  • 打赏
  • 举报
回复
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 Sub Form_Load()
MsgBox getlayout, vbInformation, "当前输入法"
End Sub

Function getlayout() As String
Dim buff As Long
getlayout = "英文输入法"
buff = GetKeyboardLayout(0) '取得目前的输入法
If ImmIsIME(buff) = 1 Then '中文输入法
getlayout = Space(255)
ImmGetDescription buff, getlayout, Len(getlayout)
End If
End Function
northwolves 2004-12-09
  • 打赏
  • 举报
回复
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 Sub Form_Load()
MsgBox getlayout, vbInformation, "当前输入法"
End Sub

Function getlayout() As String
Dim buff As Long
getlayout = "英文输入法"
buff = GetKeyboardLayout(0) '取得目前的输入法
If ImmIsIME(buff) = 1 Then '中文输入法
getlayout = Space(255)
ImmGetDescription buff, getlayout, Len(getlayout)
If InStr(getlayout, "智能ABC") > 0 Or InStr(getlayout, "全拼") > 0 Or InStr(getlayout, "双拼") > 0 Or InStr(getlayout, "拼音") > 0 Then
getlayout = "拼音输入法"
ElseIf InStr(getlayout, "五笔") > 0 Then
getlayout = "五笔输入法"
Else
getlayout = "其他输入法"
End If
End If
End Function
幻影时空 2004-12-09
  • 打赏
  • 举报
回复
呀,我发...出的速度太慢,没想到..结果已经在楼上了!
幻影时空 2004-12-09
  • 打赏
  • 举报
回复
这样也不错呀!

一个置疑的问题:ByRef IME() As String
ime该输入什么?比如说?
wwqna 2004-12-09
  • 打赏
  • 举报
回复
Private Declare Function GetKeyboardLayout Lib "user32" (ByVal dwLayout As Long) As Long
Private Declare Function GetKeyboardLayoutList Lib "user32" (ByVal nBuff As Long, lpList As Long) As Long
Private Declare Function ImmIsIME Lib "imm32.dll" (ByVal HKL 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 ActivateKeyboardLayout Lib "user32" (ByVal HKL As Long, ByVal flags As Long) As Long

Private Sub Command1_Click()
Dim ime() As String
GetIMEList ime
Dim i As Integer
For i = 0 To UBound(ime)
Debug.Print ime(i)
Next
End Sub
Sub GetIMEList(ByRef ime() As String)
Dim NoOfKBDLayout As Long, i As Long, j As Long, hCurKBDLayout As Long
Dim hKB(24) As Long, BuffLen As Long
Dim buff As String
Dim RetStr As String
Dim RetCount As Long
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)
Else
RetStr = "English (American)"
End If
ReDim Preserve ime(i - 1) As String
ime(i - 1) = RetStr
Next i
ActivateKeyboardLayout hCurKBDLayout, 0
End Sub

'输出结果
智能ABC输入法 5.0 版
王码五笔型输入法86版
智能ABC输入法 5.0 版

根本就没有去调试,用过才有发言权!
cindytsai 2004-12-09
  • 打赏
  • 举报
回复
是吗?我以为高手出招,真把问题解决了,原来。。。那还得要关注
Jeffery0211 2004-12-09
  • 打赏
  • 举报
回复
这样只能判断是中文输入法还是英文输入法吧,我想请教如何用api判断输入法是五笔输入法还是拼音输入法!谢谢!
cindytsai 2004-12-08
  • 打赏
  • 举报
回复
居然还真可以判断的,好高的高手啊,学习!
wwqna 2004-12-08
  • 打赏
  • 举报
回复
' 获得系统中的输入法列表
' IME() 为返回的输入法列表数组
Sub GetIMEList(ByRef IME() As String)
Dim NoOfKBDLayout As Long, i As Long, j As Long, hCurKBDLayout As Long
Dim hKB(24) As Long, BuffLen As Long
Dim buff As String
Dim RetStr As String
Dim RetCount As Long
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)
Else
RetStr = "English (American)"
End If
ReDim Preserve IME(i - 1) As String
IME(i - 1) = RetStr
Next i
ActivateKeyboardLayout hCurKBDLayout, 0
End Sub

1,486

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧