使用“SendMessage”发送应用程序击键(vb.net)
到目前为止,我已经设置了所有句柄捕获和 GUI。我对如何执行实际步骤感到困惑。
我有这段代码:
SendMessage(New IntPtr(CurrentHandle), WHAT,GOES,HERE?)
我一直在看: http://msdn.microsoft.com/en-us/库/ms644950(VS.85).aspx 和 http://msdn.microsoft.com/ en-us/library/ms644927(v=VS.85).aspx#system_define
但是,这些都没有提供我需要学习如何执行此操作的大量“代码示例”方法。我只需要发送按键事件,例如按“/”或“w”等。不,我不能为此使用sendkeys。
如果您能提供帮助,谢谢!
So far, I have all the handle capturing and gui set up. I'm stumped as to how to perform the actual step.
I have this code:
SendMessage(New IntPtr(CurrentHandle), WHAT,GOES,HERE?)
I've been looking at:
http://msdn.microsoft.com/en-us/library/ms644950(VS.85).aspx
and
http://msdn.microsoft.com/en-us/library/ms644927(v=VS.85).aspx#system_defined
However, none of these are giving much of the "code example" method that I need to learn how to do it. I just need to send key events such as pressing "/" or "w", etc. No, I can't use sendkeys for this.
Thanks if you can help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要模拟按键,您需要模拟 keydown 和 keyup 事件,这将是您在 Msg 字段中指定的事件。 (使用 256 表示 keydown,使用 257 表示 keyup)。 wParam 和 lParam 是特定于消息的,因此对于 keyup 和 keydown,wParam 将是关键代码 (请参阅此页了解十六进制代码),lParam 包含其他杂项信息 (查看此页面)。在 vb.net 中,您可以使用 int32 作为 lParam。例如,您可以使用 0 表示 keydown,使用 65539 表示 keyup。
前任:
To simulate a keypress, you would need to simulate a keydown and keyup event, which would be what you specify in the Msg field. (Use 256 for keydown and 257 for keyup). wParam and lParam are message-specific, so for keyup and keydown, wParam would be the key code (See this page for the hexadecimal codes) and lParam contains other miscellaneous information (see this page). In vb.net you can use an int32 for lParam. For example, you can use 0 for keydown and 65539 for keyup.
Ex:
http://msdn.microsoft.com/en- us/library/ms644950(v=vs.85).aspx
hWnd - 是发送消息的窗口句柄。
Msg - 是要发送的消息类型。
WParam 和 lParam 本质上是“信息”。确切的用途取决于您发送的消息。
您在什么情况下需要使用 SendMessage 而不是 SendKeys 来模拟按键?我以前用过SendMessage,但它总是用于鼠标移动。 .SendKeys() 应该将您告诉它的任何击键发送到活动窗口。
我在 SendKeys() 之前立即使用了上面的内容,并且它总是有效。
如果这不起作用,或者您想为了使用 SendMessage 而使用 SendMessage;您需要 WM_KEYDOWN 消息的文档。 http://msdn.microsoft.com/en- us/library/ms646280(v=vs.85).aspx
您将操作位来创建正确的 lParam 值。
http://msdn.microsoft.com/en-us/library/ms644950(v=vs.85).aspx
hWnd - is the handle of the window to send the message.
Msg - is the message type to send.
WParam and lParam are essentially 'information'. The exact use will depend on the message you are sending.
What situation are you in that you need to use SendMessage instead of SendKeys to emulate keypresses? I've used SendMessage before, but it's always been for mouse movements. .SendKeys() should send whatever keystroke you tell it to the active window.
I've used the above immediately before SendKeys() and it's always worked.
If that doesn't work, or you want to use SendMessage for the sake of using SendMessage; the documentation for WM_KEYDOWN message is what you need. http://msdn.microsoft.com/en-us/library/ms646280(v=vs.85).aspx
You'll be manipulating bits to create the correct lParam value.
这是发送常见字符(例如“A”)的示例。
发送 Ctrl-A 则是另一回事了。您可能需要 WinApi.SendInput 函数。
Here is an example of sending a common character (Such as 'A')
To send Ctrl-A is another story. You Would probably need WinApi.SendInput function.