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

In Chromium, there are two types of shortcuts. The shortcuts that are supported by the Chromium application and shortcuts that are supported by the Blink engine. JxBrowser supports only the second type of shortcuts because it does not integrate the Chromium application UI.(在Chromium中,有两种快捷方式。 Chromium应用程序支持的快捷方式和Blink引擎支持的快捷方式。 JxBrowser仅支持第二种快捷方式,因为它不集成Chromium应用程序UI。)

For example, JxBrowser supports shortcuts related to the editor like Ctrl+A/⌘+A, Ctrl+C/⌘+C, and Ctrl+X/⌘+X. JxBrowser does not support Ctrl+P/⌘+P and Ctrl+F/⌘+F shortcuts as they are provided by the Chromium application UI.(例如,JxBrowser支持与编辑器相关的快捷键,例如Ctrl + A /⌘+ A,Ctrl + C /⌘+ C和Ctrl + X /⌘+ X。 JxBrowser不支持Ctrl + P /⌘+ P和Ctrl + F /⌘+ F快捷键,因为它们是Chromium应用程序用户界面提供的。)

Processing unsupported shortcuts(处理不受支持的快捷方式)

If you need to process an unsupported shortcut such as Ctrl+P/⌘+P, you can do it manually by registering the input listener like in the following sample:(如果您需要处理不受支持的快捷键(例如Ctrl + P /⌘+ P),则可以通过注册输入侦听器来手动完成,如以下示例所示:)

import static java.awt.event.KeyEvent.KEY_RELEASED;

import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.InputEventsHandler;
import com.teamdev.jxbrowser.chromium.swing.BrowserView;
import java.awt.BorderLayout;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;
import javax.swing.WindowConstants;

public class ShortcutsSample {
    public static void main(String[] args) {
        final 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) {
                if (event.isControlDown() && event.getKeyCode() == KeyEvent.VK_P
                        && event.getID() == KEY_RELEASED) {
                return false;