Today I faced the same problem: I wanted to catch Ctrl + = , which we click on thinking Ctrl + + and associate it with the magnification action. I am using the Brazilian keyboard ABNT2. When typing, to get a plus sign, I need to use the combination Shift + = , so I can not catch Ctrl + + directly. I could do as @Aqua suggested, which should catch Ctrl + Shift + = , but for me this does not seem natural. I decided to see how some applications solve this problem.
Notepad ++ associates scaling and zooming with the numbers plus and minus, respectively. This is an easy solution to the problem, but it was also not what I wanted. Mozilla Firefox , in turn, does exactly what I want: it says that Ctrl + + is a keyboard shortcut for scaling, but what it actually catches is Ctrl + = . In addition, he also understands that I am using numpad plus to increase.
How I solved the problem
So, as I decided to solve the problem: when creating the Action I associated the keyboard shortcut Ctrl + + with the zoom action, which is actually impossible to catch:
Action zoomInAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent event) { zoomIn(); } }; zoomInAction.putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, KeyEvent.CTRL_DOWN_MASK)); JMenuItem zoomInMenuItem = new JMenuItem(zoomInAction); viewMenu.add(zoomInMenuItem);
The ace in the hole is to catch the combination Ctrl + = and process it the same way:
frame.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent event) { } @Override public void keyReleased(KeyEvent event) { } @Override public void keyPressed(KeyEvent event) { if (event.isControlDown() && (event.getKeyCode() == KeyEvent.VK_EQUALS)) { zoomIn(); } } });
Thus, the interface (i.e. JMenuItem that corresponds to Action ) tells the user to use the Ctrl + + key shortcut to enlarge. Then the user presses Ctrl + = , thinking about Ctrl + + , but the application understands this combination and acts as the user expects it.
This is my first answer, so I apologize for everything :)