It's bad to work with numeric constants. I can provide running example in Groovy, that will proof that Robot.keyPress(KeyEvent.VK_CONTROL)
is working perfectly. May it be, that you forgot call releaseKey
?
P.S. Tested on Macos Maveric with Java 1.6 with such snippet.(Groovy)
EDITED (I may suppose, you need to change Ctrl and F12 release order. F12 should be released, while Ctrl is still pressed, then modifiers will be setted correctly, and F12 will be treated as Ctrl+F12)
new SwingBuilder().frame(pack: true, show: true, defaultCloseOperation: JFrame.EXIT_ON_CLOSE) {
textField(keyPressed: { KeyEvent e ->
println("$e.keyCode, $e.modifiers") // prints 123 2 in response to Robot event.
if (e.keyCode == KeyEvent.VK_SPACE)
{
new Robot().with {
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_F12);
robot.keyRelease(KeyEvent.VK_F12); // Release it first.
robot.keyRelease(KeyEvent.VK_CONTROL);
} } }) }