Accelerator Key Value java.awt.event.KeyEvent

I use accelerator to execute CTRL + C , then CTRL + V using java / junit is there a way to get the value of CTRL + V to check it?

+4
source share
2 answers

As mentioned here , the path of a menu accelerator key, such as Ctrl + V , must be constructed in a platform-independent manner:

int mask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); JMenuItem menuItem = new JMenuItem(…); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, mask)); 

For comparison, you can get the KeyStroke menu KeyStroke via getAccelerator() or from any KeyEvent via KeyStroke.getKeyStrokeForEvent() .

+1
source

If you mean, how do I simulate the ctrl + V and ctrl + C events in a JUnit test for a Swing application, I would recommend looking at FEST . Using FEST, you can simulate mouse clicks or keystrokes. To simulate ctrl + V , you would do:

 // import static java.awt.event.KeyEvent.*; dialog.list("employees").pressKey(VK_CONTROL) .pressAndReleaseKey(VK_V) .releaseKey(VK_CONTROL); 

etc. For more information on modeling user input, see Wiki Simulating Keyboard Input .

+1
source

Source: https://habr.com/ru/post/1391658/


All Articles