To move the caret of a JTextArea downward vertically without pressing the DOWN key, is it possible to do that programmatically?
In fact I want to write it in a KeyListener, but if I write like this:
if((e.getKeyCode() == KeyEvent.VK_I) && ((e.getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0)) {
try {
new Robot().keyPress(KeyEvent.VK_UP);
} catch (AWTException e) {
e.printStackTrace();
}
}
the UP key will be combined with the mac command key, and it becomes a page up action. So how can I deal with it?
Thanks for reading my question.
I think to solve your problem instead of using
Robot
just need to suppress current event and generate new:FYI: Look to STDOUT. I think for any case you should suppress VK_I event in
keyRelease
handler too.