简体   繁体   English

在 Delphi 中禁用 TWebBrowser 上的键盘

[英]Disable keyboard on TWebBrowser in Delphi

I want Disable Keyboard for TWebBrowser and avoid copying information inside it using Ctrl+C .我想为TWebBrowser禁用键盘并避免使用Ctrl+C在其中复制信息。 but I couldn't find any option for disable keyboard in TWebBrowser properties.但我在TWebBrowser属性中找不到任何禁用键盘的选项。

Is there a way to do this?有没有办法做到这一点?

EDIT: I saw this solution but it doesn't work.编辑:我看到了这个解决方案,但它不起作用。 Disable All Keypresses禁用所有按键

You can do that at the application level, preventing some messages to be forwarded to the TWebBrowser component.您可以在应用程序级别执行此操作,防止将某些消息转发到TWebBrowser组件。 For example by using a TApplicationEvents component and its OnMessage event handler:例如,通过使用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;

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一个更干净的解决方案可能是在组件级别抑制此类消息,但不幸的是,我从未找到一种方法可以使其与TWebBrowser组件一起使用

@Fabrizio @法布里齐奥

Thank you for your code.谢谢你的代码。 this code can not Disable Keyboard for TWebBrowser.此代码无法禁用 TWebBrowser 的键盘。 For this problem I found a component called EmbeddedWB .对于这个问题,我找到了一个名为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;结尾;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM