【问题标题】:Enter key not working in HTML form using TWebBrowser component使用 TWebBrowser 组件输入键在 HTML 表单中不起作用
【发布时间】:2019-02-05 10:14:05
【问题描述】:

我用简单的文本表单制作了一个 php 网页,并尝试使用 TWebBrowser 组件在 Delphi 中使用应用程序浏览此页面。问题是我无法在此表单中按 Enter 键来获取换行符。我可以输入,鼠标工作正常,但 Enter 键不起作用。在任何其他浏览器中它都可以正常工作。 也许它可能与 TWebBrowser 的 OnEnter 事件处理程序有关?我真的不知道如何解决这个问题。

【问题讨论】:

  • 你能做一个小的静态网页来重现这个错误吗?我想我可能有一个解决方案。
  • 这里是原始的 php 脚本来测试它:alternativnaterapija.com/notes

标签: delphi twebbrowser


【解决方案1】:
procedure TForm1.FormKeyPress(Sender: TObject;var Key: Char);
begin 
  //Don't forget to set the Keypreview property 
  //of the form to true!
  if (Key=#13) then begin 
    Key := #0; 
    Keybd_Event(VK_LCONTROL, 0, 0, 0); //Ctrl key down 
    Keybd_Event(Ord('M'), MapVirtualKey(Ord('M'), 0),0, 0); // 'M' key down 
    Keybd_Event(Ord('M'), MapVirtualKey(Ord('M'), 0), KEYEVENTF_KEYUP, 0); // 'M' Key up 
    Keybd_Event(VK_LCONTROL, 0, KEYEVENTF_KEYUP,  0); // Ctrl key up 
    Keybd_Event(VK_CANCEL, 0, 0, 0);
  end; 
end;

// 来源:http://beensoft.blogspot.com/2007/10/fooling-around-with-twebbrowser-4.html
// Keypreview 改变 true

【讨论】:

    猜你喜欢
    • 2010-11-28
    • 2018-10-29
    • 1970-01-01
    • 2011-11-09
    • 2017-04-18
    • 2021-11-23
    • 1970-01-01
    • 2012-11-10
    • 1970-01-01
    相关资源
    最近更新 更多