我最近在用VB做一個串口通信上位機,想法是通過單片機發過來的資料,可以呼叫出輸入法(比方說搜狗),再用傳來的資料模擬鍵盤操作,即比如串口接收到“f”是,就相當于按下了鍵盤上的f鍵,輸入法上就顯示出“賦”、“發”、“非”這些字,再當接收到“a”字符時,輸入法中就顯示出了“發”、“法”、“罰”這些漢字,從而我可以在VB文本框中打出我想要說的一句話,甚至一段話。不知道有沒有懂我的意思,簡單點說,就是通過接收單片機發到串口的字符(asiic值),來模擬鍵盤相應的按鍵按下,從而實作了一個虛擬鍵盤的功能。但我不知道思路,也不知道是否該用API和怎樣用API。希望論壇里的大牛們可以給我些指點,謝謝!
uj5u.com熱心網友回復:
在MSDN里面搜SendInput ?uj5u.com熱心網友回復:
可以說得具體一點嗎?
uj5u.com熱心網友回復:
難道這張帖子的關注度不夠高嗎?uj5u.com熱心網友回復:
查MSDN是Windows程式員必須掌握的技能之一。uj5u.com熱心網友回復:
不好意思老師,我查了這么多天資料,還是沒有頭緒~
uj5u.com熱心網友回復:
Platform Builder for Microsoft Windows CE 5.0SendInputSee 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.
uj5u.com熱心網友回復:
https://www.baidu.com/s?ie=utf-8&f=3&rsv_bp=0&rsv_idx=1&tn=baidu&wd=SendInput&rsv_pq=c9d9d58b00028827&rsv_t=f24ebgOiVKGn0quHzUpHL8C37pdCpmpqpioDgdaOJZ6Rs3cI%2F3O%2FNAzF66s&rsv_enter=0&rsv_sug3=9&rsv_sug1=6&rsv_sug7=100&prefixsug=SendInput&rsp=0&inputT=4400&rsv_sug4=4401
uj5u.com熱心網友回復:
有一個用戶控制元件,你可以下載下來,這個好像是一個虛擬鍵盤,可以切換輸入法,如果你下載不了,聯系我。http://download.csdn.net/detail/dongfangbai/2035301
uj5u.com熱心網友回復:
我下了,但是打不開,也不知道是什么檔案格式
uj5u.com熱心網友回復:
用戶控制元件,還沒有生成OCX控制元件格式,你難道沒有將它生成控制元件格式嗎?uj5u.com熱心網友回復:
老師,這是什么啊,請原諒我水平低啊,我看不明白。
請問我可以加您的QQ向您請教嗎?
uj5u.com熱心網友回復:
沒有啊,我下下來就是圖片rar檔案的樣子,我也不知道這是個什么啊?不會用
uj5u.com熱心網友回復:
搜“使用SendInput模擬輸入”?uj5u.com熱心網友回復:
在VB中使用sendinput函式是不是得要用API函式,可是我按照教程不能夠調出“API瀏覽器”。彈出視窗顯示“由于部件(API 瀏覽器)不回應,該操作不能完成。選擇“切換到”按鈕激活該部件,改正該問題”怎么回事啊?點了“切換到“按鈕之后,就顯示出”發生意外錯誤,錯誤號:48,加載DLL錯誤“。我好心煩啊~

uj5u.com熱心網友回復:
小盆友,別整的這么復雜了。就用最基本的Sendkey就可以了。饅頭要一口一口的吃。先Sendkey Ctrl+空格,然后再Sendkey 拼音字母+空格,精確點呢就調個五筆輸入法,然后SendKeys。
再復雜一些,資料庫把常用字建個表,弄個拼音欄位,你直接用串口發來的字符搜索對應的漢字,也可以炊訓用。
uj5u.com熱心網友回復:
串口資料直接發送漢字,這個沒問題吧。然后把漢字放剪切板里面,給文本視窗發ctrl V,應該能達到要求。
用串口發的按鍵,再經過出入法,最后上去到文本框的字,可能不是你要的,要是輸入法開啟字符頻率調整咋辦。。。
uj5u.com熱心網友回復:
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: [email protected]
'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
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/60977.html
標籤:API
上一篇:菜鳥提問vb做出入庫的問題
