简体   繁体   中英

How to declare KeyStroke - pressed and released?

I want to know how to declare new KeyStroke - pressed and released? For example I can do:

KeyStroke.getKeyStroke("pressed F10");
KeyStroke.getKeyStroke("released F10");

But how to write in a way like this?:

KeyStroke.getKeyStroke(KeyEvent.VK_F10, 0);

There is a method with an additional boolean argument for this

KeyStroke.getKeyStroke(int keyCode, int modifiers, boolean onKeyRelease)

The method you discovered works on key press, so this:

KeyStroke.getKeyStroke(KeyEvent.VK_F10, 0);

is equivalent to

KeyStroke.getKeyStroke(KeyEvent.VK_F10, 0, false);

If you want to get this working on the release of F10 , use

KeyStroke.getKeyStroke(KeyEvent.VK_F10, 0, true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM