我正在尝试在外部应用程序的 mdi 子窗口上使用 sendinput API 向其发送键/鼠标输入以进行数学运算。我有窗口句柄 id 并使用 setfocus windows API 对其进行 setfocus,但 sendinput 不会发送密钥。我选择允许数值的接收控件。此外,我需要一些数值作为十进制输入发送,例如 3.3。如果您需要外部应用程序的图像,请在下面发表评论,我将在我的谷歌驱动器帐户上发布图像。
......
Dim hNoteThread As IntPtr = GetWindowThreadProcessId(windowids(foundid), IntPtr.Zero)
If hNoteThread <> 0 Then
MsgBox("Panel 0 found for input")
End If
' SetForegroundWindow(windowids(foundid))
If AttachThreadInput(GetCurrentThreadId(), hNoteThread, True) = True Then
SetFocus(windowids(foundid))
System.Threading.Thread.Sleep(1000)
SendKey(VK_TAB)
System.Threading.Thread.Sleep(2000)
SendKey(VK_NUMPAD2)
System.Threading.Thread.Sleep(2000)
SendKey(VK_TAB)
SendKey(VK_NUMPAD0 + VK_DECIMAL + VK_NUMPAD5)
' System.Threading.Thread.Sleep(1000)
SendKey(VK_TAB)
SendKey(VK_NUMPAD1)
' System.Threading.Thread.Sleep(1000)
SendKey(VK_TAB)
SendKey(VK_NUMPAD2)
System.Threading.Thread.Sleep(2000)
MsgBox("keys sent")
Else
MsgBox("keys not sent")
End If
Private Sub SendKey(ByVal bKey As Short)
Dim GInput(1) As INPUT
' press the key
GInput(0).type = INPUT_KEYBOARD
GInput(0).ki.wVk = bKey
GInput(0).ki.dwFlags = 0
' release the key
GInput(1).type = INPUT_KEYBOARD
GInput(1).ki.wVk = bKey
GInput(1).ki.dwFlags = KEYEVENTF_KEYUP
SendInput(2, GInput, Marshal.SizeOf(GetType(INPUT)))
End Sub
编辑:这是一个图像的链接,因此有人可以弄清楚需要如何发送输入: https ://drive.google.com/file/d/0BwIppJC0dxJBalp3Ykd2VzZkQ0E/edit?usp=sharing
发送输入的目标控件是 Psi、D 和其他可以在 Panel0 中更改的值,我也需要单击按钮。
问题是发送输入根本无法工作,我的消息框显示输入已发送。