There is another simpler option: you can press alt in the program and then release it the same way:
public static void pressAlt(){ try { Robot r = new Robot(); r.keyPress(KeyEvent.VK_ALT); } catch (AWTException ex) { Logger.getLogger(ManualDetection.class.getName()).log(Level.SEVERE, null, ex); } } public static void releaseAlt(){ try { Robot r = new Robot(); r.keyRelease(KeyEvent.VK_ALT); } catch (AWTException ex) { Logger.getLogger(ManualDetection.class.getName()).log(Level.SEVERE, null, ex); } }
then when calling:
pressAlt(); int confirm = JOptionPane.showConfirmDialog(... bla bla bla ... ,JOptionPane.YES_NO_OPTION); releaseAlt();
the behavior is exactly the same as you wanted ...
v.mic source share