Note: Advice in this article will only work for JxBrowser 6. See the corresponding article for JxBrowser 7 here.(注意:本文中的建议仅适用于JxBrowser6,JxBrowser7相应文章请点击这里。)

Using the BrowserView.setKeyEventsHandler(InputEventsHandler<KeyEvent> handler) method you can decide what keyboard events should be suppressed before they will be sent to Chromium engine. The following example demonstrates how to disable the Ctrl+A shortcut:(使用BrowserView.setKeyEventsHandler(InputEventsHandler handler)方法,您可以决定在将哪些键盘事件发送到Chromium引擎之前,将它阻止。下面的示例演示如何禁用Ctrl + A快捷键:)

import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.InputEventsHandler;
import com.teamdev.jxbrowser.chromium.swing.BrowserView;

import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;

 * This sample demonstrates how to register key events handler to handle/suppress
 * Ctrl+A key events (e.g. to prevent text selection).
public class KeyEventsHandlerSample {
    public static void main(String[] args) {
        Browser browser = new Browser();
        BrowserView view = new BrowserView(browser);

        JFrame frame = new JFrame();
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(700, 500);

        view.setKeyEventsHandler(new InputEventsHandler<KeyEvent>() {
            public boolean handle(KeyEvent event) {
                return event.isControlDown() && event.getKeyCode() == KeyEvent.VK_A;