在Delphi中禁用Twebbrowser上的键盘

发布于 2025-02-01 00:34:11 字数 286 浏览 1 评论 0原文

我想禁用twebbrowser的键盘,并避免使用 ctrl+ctrl+c 复制其中的信息。但是我找不到在twebbrowser属性中禁用键盘的任何选项。

有办法这样做吗?

编辑:我看到了这个解决方案,但它不起作用。 禁用所有键

I want Disable Keyboard for TWebBrowser and avoid copying information inside it using Ctrl+C. but I couldn't find any option for disable keyboard in TWebBrowser properties.

Is there a way to do this?

EDIT: I saw this solution but it doesn't work.
Disable All Keypresses

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

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

发布评论

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

评论(2

巡山小妖精 2025-02-08 00:34:11

您可以在应用程序级别上执行此操作,以防止将某些消息转发到twebbrowser组件。例如,通过使用tapplicationEvents组件及其onMessage事件处理程序:

procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
  var Handled: Boolean);
begin
  if (
    //keyboard
    (Msg.message = WM_KEYDOWN)
    //right click, for avoid copy-paste from popupmenu
    (Msg.Message = WM_RBUTTONDOWN) or
    (Msg.Message = WM_RBUTTONDBLCLK) or
  ) then
  begin
    if IsChild(WebBrowser1.Handle, Msg.hwnd) then
    begin
      Handled := True;
    end;
  end;
end;

一个清洁的解决方案可以是在组件级别抑制此类消息,但是没有派遣的方法,但是我从未找到过一种方法为了使其与twebbrowser组件一起使用

You can do that at the application level, preventing some messages to be forwarded to the TWebBrowser component. For example by using a TApplicationEvents component and its OnMessage event handler:

procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
  var Handled: Boolean);
begin
  if (
    //keyboard
    (Msg.message = WM_KEYDOWN)
    //right click, for avoid copy-paste from popupmenu
    (Msg.Message = WM_RBUTTONDOWN) or
    (Msg.Message = WM_RBUTTONDBLCLK) or
  ) then
  begin
    if IsChild(WebBrowser1.Handle, Msg.hwnd) then
    begin
      Handled := True;
    end;
  end;
end;

A cleaner solution could be to suppress such messages at the component level, but unforntunately I've never found a way to make that works with the TWebBrowser component

攀登最高峰 2025-02-08 00:34:11

@fabrizio

谢谢您的代码。此代码无法为Twebbrowser禁用键盘。
对于这个问题,我找到了一个称为 embeddedwb 的组件。它具有禁用上下文菜单的选项。

现在,使用您的代码(稍有更改)的复合选项使文本复制完全禁用。

procedure TMainForm.ApplicationEventsMessage(var Msg: tagMSG;
 var Handled: Boolean);
begin
 if ((Msg.message=WM_RBUTTONDOWN) or (Msg.message=WM_RBUTTONUP) or 
    (Msg.message=WM_KEYDOWN) or (Msg.message=WM_KEYUP)) and 
    IsChild(WebBrowser.Handle,Msg.hwnd) then
    begin
     PopupMenu.Popup(Msg.pt.X,Msg.pt.Y);
     Handled:=true;
 end;

结尾;

@Fabrizio

Thank you for your code. this code can not Disable Keyboard for TWebBrowser.
For this problem I found a component called EmbeddedWB. It have options for disable context menu.

Now Compound Options with your code (with a little change) makes text copying completely disabled.

procedure TMainForm.ApplicationEventsMessage(var Msg: tagMSG;
 var Handled: Boolean);
begin
 if ((Msg.message=WM_RBUTTONDOWN) or (Msg.message=WM_RBUTTONUP) or 
    (Msg.message=WM_KEYDOWN) or (Msg.message=WM_KEYUP)) and 
    IsChild(WebBrowser.Handle,Msg.hwnd) then
    begin
     PopupMenu.Popup(Msg.pt.X,Msg.pt.Y);
     Handled:=true;
 end;

end;

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