是否可以将密钥/发布消息直接发送到 HtmlElement 而不是 Web 浏览器控件?

发布于 2024-08-29 17:05:02 字数 418 浏览 4 评论 0原文

我想直接将密钥发送到 ac# Web 浏览器控制元素,而不仅仅是具有正确焦点的窗口。

现在我可以使用 PostMessage 和 documentHandle 发送密钥,并像这样聚焦

,即伪代码

HtmlElement el = getelement();
el.Focus();
IntPtr docptr = browser.Handle;
PostMessage(docptr,WM_KEYDOWN,1,0);
.... KEYCHAR, KEYUP..

我想知道是否有人知道有什么方法可以在后台执行此操作,以便焦点不在元素上。基本上有一种方法可以将 IntPtr 获取到 HtmlElement 本身,而不是在 PostMessage 或 SendKeys API 中使用它,而不是在浏览器句柄/ptr 中使用它。

I would like to send keys to a c# web browser control element directly, not just the window with the correct focus.

Right now I am able to send a key using PostMessage and documentHandle and focus like this

i.e. Pseudo Code

HtmlElement el = getelement();
el.Focus();
IntPtr docptr = browser.Handle;
PostMessage(docptr,WM_KEYDOWN,1,0);
.... KEYCHAR, KEYUP..

I was wondering if anyone knows of any way to be able to do this in a background, so that the focus is not on the element. Basically is there a way to get a IntPtr to the HtmlElement itself, than use that instead in the PostMessage or SendKeys API rather than the browser handle/ptr.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

來不及說愛妳 2024-09-05 17:05:03

你不能。这些是无窗口控件,鼠标/键盘消息由其父窗口处理,并且父窗口仅中继活动控件的消息。

You can't. Those are windowless controls, mouse/keyboard messages are handled by their parent window, and the parent only relay message for the active control.

你列表最软的妹 2024-09-05 17:05:03

这是错误的做法。

您可以使用 HtmlElement API 直接操作元素。

如需准确的说明,请告诉我们您想要做什么。

This is the wrong way to go.

You can use the HtmlElement API to manipulate the element directly.

For precise instructions, please tell us what you're trying to do.

睡美人的小仙女 2024-09-05 17:05:03

看看 WaitN 和 Selenium 之类的东西。

IE也有一个很好的编程接口来控制浏览器。

但也有缺点......

我目前正在开发一个程序,该程序使用图像识别和鼠标/按键控制来控制浏览器,因为我只能通过视觉表示真正做我想做的事情。

然而,这将主宰计算机并需要完全控制。除非你在虚拟机中运行它。

Have a look at things like WaitN and Selenium.

IE also has a good programming interface to control the browser.

But there are downsides...

I'm currently working on a program that uses image recognition and control of the mouse/keys to control a browser as I can only really do what I want with the visual representation.

However that will dominate the computer and need full control. Unless you run it in a virtual machine.

妖妓 2024-09-05 17:05:03

我花了很长时间才找到这一点,但是您必须使用子命令 p/invoke GetWindow 来重复获取子窗口句柄,直到找到一个使用“Internet Explorer_Server”或类似内容响应 GetClassName 的窗口句柄。

然后该 hWnd 上的 PostMessage 和 WebBrowser 的 activeElement 将接收它们。确保其中有 WM_KEYUP,因为这似乎很重要。

It took me a long time to find this, but you have to p/invoke GetWindow with the child command to repeatedly get child window handles until you get down to one that responds to GetClassName with "Internet Explorer_Server" or something like that.

Then PostMessage on that hWnd and the activeElement of the WebBrowser will recieve them. Make sure you have the WM_KEYUP in there as that seems to be the important one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文