VB调用本机输入法

yuan_ahah 2016-04-21 09:54:13
我最近在用VB做一个串口通信上位机,想法是通过单片机发过来的数据,可以调用出输入法(比方说搜狗),再用传来的数据模拟键盘操作,即比如串口接收到“f”是,就相当于按下了键盘上的f键,输入法上就显示出“赋”、“发”、“非”这些字,再当接收到“a”字符时,输入法中就显示出了“发”、“法”、“罚”这些汉字,从而我可以在VB文本框中打出我想要说的一句话,甚至一段话。不知道有没有懂我的意思,简单点说,就是通过接收单片机发到串口的字符(asiic值),来模拟键盘相应的按键按下,从而实现了一个虚拟键盘的功能。但我不知道思路,也不知道是否该用API和怎样用API。希望论坛里的大牛们可以给我些指点,谢谢!
...全文
7156 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2017-03-28
  • 打赏
  • 举报
回复
Const VK_H = 72
Const VK_E = 69
Const VK_L = 76
Const VK_O = 79
Const KEYEVENTF_KEYUP = &H2
Const INPUT_MOUSE = 0
Const INPUT_KEYBOARD = 1
Const INPUT_HARDWARE = 2
Private Type MOUSEINPUT
  dx As Long
  dy As Long
  mouseData As Long
  dwFlags As Long
  time As Long
  dwExtraInfo As Long
End Type
Private Type KEYBDINPUT
  wVk As Integer
  wScan As Integer
  dwFlags As Long
  time As Long
  dwExtraInfo As Long
End Type
Private Type HARDWAREINPUT
  uMsg As Long
  wParamL As Integer
  wParamH As Integer
End Type
Private Type GENERALINPUT
  dwType As Long
  xi(0 To 23) As Byte
End Type
Private Declare Function SendInput Lib "user32.dll" (ByVal nInputs As Long, pInputs As GENERALINPUT, ByVal cbSize As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
Private Sub Form_KeyPress(KeyAscii As Integer)
    'Print the key on the form
    Me.Print Chr$(KeyAscii);
End Sub
Private Sub Form_Paint()
    'KPD-Team 2000
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
    'Clear the form
    Me.Cls
    'call the SendKey-function
    SendKey VK_H
    SendKey VK_E
    SendKey VK_L
    SendKey VK_L
    SendKey VK_O
End Sub
Private Sub SendKey(bKey As Byte)
    Dim GInput(0 To 1) As GENERALINPUT
    Dim KInput As KEYBDINPUT
    KInput.wVk = bKey  'the key we're going to press
    KInput.dwFlags = 0 'press the key
    'copy the structure into the input array's buffer.
    GInput(0).dwType = INPUT_KEYBOARD   ' keyboard input
    CopyMemory GInput(0).xi(0), KInput, Len(KInput)
    'do the same as above, but for releasing the key
    KInput.wVk = bKey  ' the key we're going to realease
    KInput.dwFlags = KEYEVENTF_KEYUP  ' release the key
    GInput(1).dwType = INPUT_KEYBOARD  ' keyboard input
    CopyMemory GInput(1).xi(0), KInput, Len(KInput)
    'send the input now
    Call SendInput(2, GInput(0), Len(GInput(0)))
End Sub
王二.麻子 2017-03-27
  • 打赏
  • 举报
回复
串口数据直接发送汉字,这个没问题吧。 然后把汉字放剪切板里面,给文本窗口发ctrl V,应该能达到要求。 用串口发的按键,再经过出入法,最后上去到文本框的字,可能不是你要的,要是输入法开启字符频率调整咋办。。。
wuke_615 2017-03-14
  • 打赏
  • 举报
回复
小盆友,别整的这么复杂了。就用最基本的Sendkey就可以了。馒头要一口一口的吃。 先Sendkey Ctrl+空格,然后再Sendkey 拼音字母+空格,精确点呢就调个五笔输入法,然后SendKeys。 再复杂一些,数据库把常用字建个表,弄个拼音字段,你直接用串口发来的字符搜索对应的汉字,也可以凑活用。
赵4老师 2016-04-25
  • 打赏
  • 举报
回复
Platform Builder for Microsoft Windows CE 5.0 SendInputSee Also keybd_event | mouse_event | PostKeybdMessage | INPUT | Keyboard Functions Requirements OS Versions: Windows CE 2.0 and later. Header: Winuser.h. Link Library: Wmgr_c.lib, Uibase.lib. This function synthesizes keystrokes, stylus and mouse motions, and button clicks. UINT SendInput( UINT nInputs, LPINPUT pInputs, int cbSize ); Parameters nInputs Specifies how many structures pInputs points to. pInputs Pointer to an array of INPUT structures. Each structure represents an event to be inserted into the keyboard or mouse input stream. cbSize Specifies the size of an INPUT structure. If cbSize is not the size of an INPUT structure, the function will fail. Return Values The number of events that the function inserted into the keyboard or mouse input stream indicates success. To get extended error information, call GetLastError. Remarks Windows CE does not support the INPUT_HARDWARE value in the type field of the INPUT structure referred to by the pInputs parameter. The SendInput function inserts the events in the INPUT structures serially into the keyboard or mouse input stream. These events are not interspersed with other keyboard or mouse input events inserted either by the user (with the keyboard or mouse) or by calls to keybd_event, mouse_event, or other calls to SendInput. Requirements OS Versions: Windows CE 2.0 and later. Header: Winuser.h. Link Library: Wmgr_c.lib, Uibase.lib. See Also keybd_event | mouse_event | PostKeybdMessage | INPUT | Keyboard Functions -------------------------------------------------------------------------------- Last updated on Wednesday, September 14, 2005 © 2005 Microsoft Corporation. All rights reserved.
yuan_ahah 2016-04-25
  • 打赏
  • 举报
回复
引用 4 楼 zhao4zhong1 的回复:
查MSDN是Windows程序员必须掌握的技能之一。
不好意思老师,我查了这么多天资料,还是没有头绪~
yuan_ahah 2016-04-25
  • 打赏
  • 举报
回复
引用 13 楼 zhao4zhong1 的回复:
搜“使用SendInput模拟输入”?

在VB中使用sendinput函数是不是得要用API函数,可是我按照教程不能够调出“API浏览器”。弹出窗口显示“由于部件(API 浏览器)不响应,该操作不能完成。选择“切换到”按钮激活该部件,改正该问题”怎么回事啊?点了“切换到“按钮之后,就显示出”发生意外错误,错误号:48,加载DLL错误“。我好心烦啊~
赵4老师 2016-04-25
  • 打赏
  • 举报
回复
搜“使用SendInput模拟输入”?
yuan_ahah 2016-04-25
  • 打赏
  • 举报
回复
引用 10 楼 u013249970 的回复:
用户控件,还没有生成OCX控件格式,你难道没有将它生成控件格式吗?

没有啊,我下下来就是图片rar文件的样子,我也不知道这是个什么啊?不会用
yuan_ahah 2016-04-25
  • 打赏
  • 举报
回复
引用 6 楼 zhao4zhong1 的回复:
Platform Builder for Microsoft Windows CE 5.0 SendInputSee Also keybd_event | mouse_event | PostKeybdMessage | INPUT | Keyboard Functions Requirements OS Versions: Windows CE 2.0 and later. Header: Winuser.h. Link Library: Wmgr_c.lib, Uibase.lib. This function synthesizes keystrokes, stylus and mouse motions, and button clicks. UINT SendInput( UINT nInputs, LPINPUT pInputs, int cbSize ); Parameters nInputs Specifies how many structures pInputs points to. pInputs Pointer to an array of INPUT structures. Each structure represents an event to be inserted into the keyboard or mouse input stream. cbSize Specifies the size of an INPUT structure. If cbSize is not the size of an INPUT structure, the function will fail. Return Values The number of events that the function inserted into the keyboard or mouse input stream indicates success. To get extended error information, call GetLastError. Remarks Windows CE does not support the INPUT_HARDWARE value in the type field of the INPUT structure referred to by the pInputs parameter. The SendInput function inserts the events in the INPUT structures serially into the keyboard or mouse input stream. These events are not interspersed with other keyboard or mouse input events inserted either by the user (with the keyboard or mouse) or by calls to keybd_event, mouse_event, or other calls to SendInput. Requirements OS Versions: Windows CE 2.0 and later. Header: Winuser.h. Link Library: Wmgr_c.lib, Uibase.lib. See Also keybd_event | mouse_event | PostKeybdMessage | INPUT | Keyboard Functions -------------------------------------------------------------------------------- Last updated on Wednesday, September 14, 2005 © 2005 Microsoft Corporation. All rights reserved.
老师,这是什么啊,请原谅我水平低啊,我看不明白。请问我可以加您的QQ向您请教吗?
ZHRXJR 2016-04-25
  • 打赏
  • 举报
回复
用户控件,还没有生成OCX控件格式,你难道没有将它生成控件格式吗?
yuan_ahah 2016-04-25
  • 打赏
  • 举报
回复
引用 8 楼 u013249970 的回复:
有一个用户控件,你可以下载下来,这个好像是一个虚拟键盘,可以切换输入法,如果你下载不了,联系我。 http://download.csdn.net/detail/dongfangbai/2035301
我下了,但是打不开,也不知道是什么文件格式
ZHRXJR 2016-04-25
  • 打赏
  • 举报
回复
有一个用户控件,你可以下载下来,这个好像是一个虚拟键盘,可以切换输入法,如果你下载不了,联系我。 http://download.csdn.net/detail/dongfangbai/2035301
赵4老师 2016-04-23
  • 打赏
  • 举报
回复
查MSDN是Windows程序员必须掌握的技能之一。
赵4老师 2016-04-22
  • 打赏
  • 举报
回复
在MSDN里面搜SendInput ?
yuan_ahah 2016-04-22
  • 打赏
  • 举报
回复
难道这张帖子的关注度不够高吗?
yuan_ahah 2016-04-22
  • 打赏
  • 举报
回复
引用 1 楼 zhao4zhong1 的回复:
在MSDN里面搜SendInput ?
可以说得具体一点吗?

1,486

社区成员

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

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