Java Swing KeyStrokes: how to make CTRL-modifier work

谁都会走 提交于 2019-12-05 03:48:16

I find it easier to use:

KeyStroke a = KeyStroke.getKeyStroke("A");
KeyStroke controlA = KeyStroke.getKeyStroke("control A");

or:

KeyStroke controlA = KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_MASK);

Dude, use this

inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_MASK), "foo");
SOA Nerd

Yep, the above code will work.

Big picture - Ctrl+a and a are read as different keystrokes the same as a and b would be different.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!