'Java Robot keypresses not picked up by global hotkey settings of other program

I've written a program that can detect the sound output of my PC (only works with StereoMix on Windows in Java from what I could find). Once there is a silence of 2-3 seconds, I trigger a keypress. Once there is a silence of 10+ seconds, I trigger a different keypress.

For the first keypress I have the program selected and it works just fine. For the second keypress, however, I have global hotkeys defined in another program. These don't get picked up when the keypresses are done by Java.

My google searches sadly seem to only find things related to not detecting a keypress event in your Java program.

The code to perform the key presses. Adding a delay in between pressing and releasing makes no difference.

Robot robot = new Robot();
robot.keyPress(KeyEvent.CTRL_DOWN_MASK);
robot.keyPress(KeyEvent.SHIFT_DOWN_MASK);
robot.keyPress(KeyEvent.VK_F12);
robot.keyRelease(KeyEvent.CTRL_DOWN_MASK);
robot.keyRelease(KeyEvent.SHIFT_DOWN_MASK);
robot.keyRelease(KeyEvent.VK_F12);


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source