Reputation: 34884
I want to catch some hotkeys with 2 letter keys like Ctrl+P,P
(Ctrl+P
and press P
without releasing Ctrl
) but code below doesn't work:
KeyStroke.getKeyStroke(KeyEvent.VK_P & KeyEvent.VK_P, InputEvent.CTRL_MASK)
//or
KeyStroke.getKeyStroke(KeyEvent.VK_P | KeyEvent.VK_P, InputEvent.CTRL_MASK)
It only captures Ctrl+P
Upvotes: 0
Views: 168
Reputation: 324118
Then you need to use two separate KeyStrokes and catch each KeyStroke separately. For example:
KeyStroke p = KeyStroke.getKeyStroke('P');
KeyStroke control = KeyStroke.getKeyStroke("control P");
Read the section from the Swing tutorial on How to Use Key Bindings for more information.
Upvotes: 2