发送消息到插入点 [英] Send a Message to insertion point
本文介绍了发送消息到插入点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以发送短信而不指定HWND吗?只需发送到插入点,我的意思是键入时该行会出现.
下面的代码不起作用.
sendmessage可以做我想要的吗?
Can i send a text message do not specify the HWND. Just send to the insertion point which i mean the line appear when you typing.
The code below do not work.
Can sendmessage do what i want?
Public Class Form1
Declare Auto Function SendMessage Lib "User32.dll" _
(ByVal hWnd As IntPtr, ByVal Msg As Integer, _
ByVal wParam As Integer, ByVal lParam As String) As Integer
Private Const WM_SETTEXT As Integer = &HC
Declare Function GetAsyncKeyState Lib "user32" Alias "GetAsyncKeyState" _
(ByVal vKey As Integer) As Integer
Dim F8 As Integer = 119
Private Sub tmr_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles tmr.Tick
If (GetAsyncKeyState(119) < 0) Then
SendMessage(0, WM_SETTEXT, 0, "12123")
End If
End Sub
End Class
推荐答案
您需要的是模拟输入事件,尤其是键事件.在这种情况下,
SendKeys
方法非常有限.它将密钥发送到活动的应用程序,但是您无法激活它;还有其他限制.
模拟输入的真正通用方法是P/Invoke Windows APISendInput
,请参见 ^ ].
在这种情况下,您不需要HWND;模拟是低级的;您可以完全模仿真实的键盘.
我警告不要将其用于UI开发或应用程序集成.这将是对技术的真正滥用.
-SA
What you need is to simulate input events, in particular key events. In this case,
TheSendKeys
method is very limited; it will send keys to an active application, but you cannot activate it; there are other limitation.
The really universal way of simulation of input is to P/Invoke Windows APISendInput
, see http://msdn.microsoft.com/en-us/library/ms646310(v=vs.85).aspx[^].
In this case you don''t need HWND; the simulation is low-level; you can fully imitate the real keyboard.
I would warn against using it for UI development or application integration; it would be a real abuse of technology.
—SA
或者您也可以使用 ^ ] ...
Or you could just use SendKeys[^]...
您只能将消息发送到窗口句柄.如果您不知道窗口句柄,则必须先找到它.
我不知道你在做什么,所以几乎不可能告诉你正确的行动是什么.
You can only send messages to window handles. If you don''t know the window handle, you must find it first.
I have no idea what you''re doing so it''s pretty much impossible to tell you what the correct corse of action is.
这篇关于发送消息到插入点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文