将 Enter 键发送到 Web 浏览器1

发布于 2024-10-21 08:03:01 字数 366 浏览 1 评论 0原文

你好

我尝试过;

PostMessage(embeddedwb1.Handle,VK_RETURN,0,0);
sendmessage(embeddedwb1,wm_keyup,vk_return,0);
embeddedwb1.perform(wm_keyup,vk_return,0);

但我的程序不起作用。 我尝试过;

Keybd_Event(VK_RETURN,   1, 0, 0);

我的程序可以运行。但这是用于发送所有应用程序的回车键的代码。我只想为我的程序编写代码。感谢您帮助我

Hello.

I tried with ;

PostMessage(embeddedwb1.Handle,VK_RETURN,0,0);
sendmessage(embeddedwb1,wm_keyup,vk_return,0);
embeddedwb1.perform(wm_keyup,vk_return,0);

but my program doesn't work.
and i tried with ;

Keybd_Event(VK_RETURN,   1, 0, 0);

my program is worked.but that is code for sending enter key for All Applications.i want to code for just my program.Thank you for helping me.

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

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

发布评论

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

评论(3

恏ㄋ傷疤忘ㄋ疼 2024-10-28 08:03:01

在调用 Keypd_Event(...) 之前,确保使用 SetFocus(embeddedwb1.Handele) 聚焦 Web 浏览器。

既然您可能想要提交表单,您是否考虑过使用 DOM 来实现这一点?下面是一些填充所选输入字段然后提交第一个表单的代码。如果您导航到 http://www.google.com,这种方法就很好用,但在现实世界中,您' d 需要更加小心(按类或 id 搜索输入字段,检查是否有表单等)

procedure TForm23.Button2Click(Sender: TObject);
begin
  ((W.Document as IHTMLDocument2).activeElement as IHTMLInputElement).value := 'Search';
  ((W.Document as IHTMLDocument2).forms.item(0, '') as IHTMLFormElement).submit;
end;

Make sure the WebBrowser is focused using SetFocus(embeddedwb1.Handele) before calling Keypd_Event(...).

Since you probably want to submit a form, did you consider doing that with the DOM? Here's some code that fills in the selected input field and then submits the first form. This works just fine if you navigate to http://www.google.com, but in the real world you'd need to be a lot more careful (search the input field by class or id, check if there's a form, etc)

procedure TForm23.Button2Click(Sender: TObject);
begin
  ((W.Document as IHTMLDocument2).activeElement as IHTMLInputElement).value := 'Search';
  ((W.Document as IHTMLDocument2).forms.item(0, '') as IHTMLFormElement).submit;
end;
奈何桥上唱咆哮 2024-10-28 08:03:01

如果 Javascript 用于提交表单,那么我认为 Cosmin 答案不起作用。在这种情况下,您必须了解按钮的 JS 代码并从您的程序中执行它。例如;在我的页面中,我使用 JQuery 提交表单。所以:

procedure TForm1.Button1Click(Sender: TObject);
var
  js_code : string;
  Win : IHTMLWindow2;
begin
  Win := (WebBrowser1.Document as IHTMLDocument2).parentWindow;
  js_code := '$("#formlogin").submit();';
  Win.execScript(js_code, 'JavaScript');
end; 

if Javascript is used for submit form then Cosmin answer doesn't work I think. In this case you must know JS code of the button and execute it from your program. For example; in my page, I use JQuery to submit form. So:

procedure TForm1.Button1Click(Sender: TObject);
var
  js_code : string;
  Win : IHTMLWindow2;
begin
  Win := (WebBrowser1.Document as IHTMLDocument2).parentWindow;
  js_code := '$("#formlogin").submit();';
  Win.execScript(js_code, 'JavaScript');
end; 
无需解释 2024-10-28 08:03:01

使用此代码:

PostMessage(EmbeddedWB1.HWND, WM_CHAR, 13, 0);

此代码将字符 13(输入代码)发送到 EmbeddedWB。

Use this:

PostMessage(EmbeddedWB1.HWND, WM_CHAR, 13, 0);

This code send char 13 (Enter code) to EmbeddedWB.

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