void injectKey(int new_key, boolean shift_pressed,
                   boolean ctrl_pressed, boolean alt_pressed,
                   boolean command_pressed) throws AWTException {

        // create Robot instance if necessary
        if (robot == null){
            robot = new Robot();
        }

        // use upper case chars
        char key = Character.toUpperCase((char) new_key);

        // set up modifier keys
        if (shift_pressed) {
            robot.keyPress(KeyEvent.VK_SHIFT);
        }
        if (ctrl_pressed) {
            robot.keyPress(KeyEvent.VK_CONTROL);
        }
        if (alt_pressed) {
            robot.keyPress(KeyEvent.VK_ALT);
        }
        if (command_pressed){
            robot.keyPress(KeyEvent.VK_META);
        }

        // inject single press
        robot.keyPress(key);
        robot.keyRelease(key);

        // unset modifier keys
        if (command_pressed){
            robot.keyRelease(KeyEvent.VK_META);
        }
        if (alt_pressed) {
            robot.keyRelease(KeyEvent.VK_ALT);
        }
        if (ctrl_pressed) {
            robot.keyRelease(KeyEvent.VK_CONTROL);
        }
        if (shift_pressed) {
            robot.keyRelease(KeyEvent.VK_SHIFT);
        }
    }