Examples‎ > ‎

Filter Keyboard Shortcuts

The following sample demonstrates how to disable Ctrl+F and Ctrl+P shortcuts:
import com.jniwrapper.win32.ie.Browser;
import com.jniwrapper.win32.ie.KeyFilter;
 
import javax.swing.*;
 
/**
 * The sample demonstrates how to disable the specified shortcuts
 * in {@code WebBrowser} component.
 */
public class DisableShortcutsSample {
    public static void main(String[] args) {
        Browser browser = new Browser();
 
        JFrame frame = new JFrame();
        frame.setContentPane(browser);
        frame.setSize(500, 300);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
 
        browser.setKeyFilter(new KeyFilter() {
            public boolean isFilter(KeyEvent evt) {
                return (evt.getKeyCode() == 'F' && evt.isControlPressed()) ||
                        (evt.getKeyCode() == 'P' && evt.isControlPressed());
            }
        });
        browser.navigate("http://www.google.com");
    }
}