How to simulate Ctrl + Shift + f1 in swing application and write to log file

awtrobot, java, swing

Solution

You can simulate key presses quite easily using the Robot class, it has methods to press and release keys.

Robot r = new Robot();
r.keyPress(KeyEvent.VK_CONTROL);
r.keyPress(KeyEvent.VK_SHIFT);
r.keyPress(KeyEvent.VK_F1);
r.keyRelease(KeyEvent.VK_F1);
r.keyRelease(KeyEvent.VK_SHIFT);
r.keyRelease(KeyEvent.VK_CONTROL);

Problem

I have this swing client-server app. I want to simulate the 'Ctrl+Shift+f1' effect programatically and write to my log4j log file for certain frames that I am loading for debugging purposes. Is there a swing method I call to turn this option on? How do I do this? Or is there a better way to know the layout while it loads and write to log file? Thanks.

Original source