So, to give a bit of context, I finally got tired of having to research for the ALT codes of certain symbols and sub/superscript numbers, and never getting it right, I suppose this mapping error have something to do with de keyboard version I'm using, but to be honest, I don't care, and to solve this problem I created a program in Java that will print all the alt codes going from Alt0000 to Alt9999 on a separate notepad window via keyPress but, I'm having problems on printing all of them, somehow it erases the text multiple times during the run, and after a while it starts printing nonsensical things.
As requested in a comment bellow, here's a print of the nonsensical things:
And for adding more details, the program runs fine for the first 100-ish codes, them it erases some of the codes and run fine until de 6000-ish codes, which is where it starts printing only the pre texts that indicate the codes and don't breaking any lines, a further more down the line it also erases the progress, and keeps with de "nonsensical things" as I am calling it.
If someone could give me some tips on how to do/fix this I would very much appreciate.
Since I'm not an expert programmer I'm also accepting tips on how to improve my code.
Thanks. :)
This is my code:
package randomProjects;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.*;
public class SimulateKeyPress {
public static void main(String[] args) throws InterruptedException {
int[] keyEvents = {KeyEvent.VK_NUMPAD0,
KeyEvent.VK_NUMPAD1,
KeyEvent.VK_NUMPAD2,
KeyEvent.VK_NUMPAD3,
KeyEvent.VK_NUMPAD4,
KeyEvent.VK_NUMPAD5,
KeyEvent.VK_NUMPAD6,
KeyEvent.VK_NUMPAD7,
KeyEvent.VK_NUMPAD8,
KeyEvent.VK_NUMPAD9};
try {
Robot robot = new Robot();
// click on notepad window positioned at the rigth of the IDE
robot.mouseMove(1000,400);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
// run trhought the thousand units
for(int um = 0; um <= 9; um++) {
// run trhought the hundreds
for(int c = 0; c <= 9; c++) {
// run trhought the dozens
for(int d = 0; d <= 9; d++) {
// run trhought the units
for(int u = 0; u <= 9; u++) {
// write the pressed keys
// alt+####
robot.keyPress(KeyEvent.VK_A);
robot.keyRelease(KeyEvent.VK_A);
robot.keyPress(KeyEvent.VK_L);
robot.keyRelease(KeyEvent.VK_L);
robot.keyPress(KeyEvent.VK_T);
robot.keyRelease(KeyEvent.VK_T);
robot.keyPress(KeyEvent.VK_ADD);
robot.keyRelease(KeyEvent.VK_ADD);
robot.keyPress(keyEvents[um]);
robot.keyRelease(keyEvents[um]);
robot.keyPress(keyEvents[c]);
robot.keyRelease(keyEvents[c]);
robot.keyPress(keyEvents[d]);
robot.keyRelease(keyEvents[d]);
robot.keyPress(keyEvents[u]);
robot.keyRelease(keyEvents[d]);
robot.keyPress(KeyEvent.VK_TAB);
// write the respective ALT CODE result
robot.keyPress(KeyEvent.VK_ALT);
robot.keyPress(keyEvents[um]);
robot.keyPress(keyEvents[c]);
robot.keyPress(keyEvents[d]);
robot.keyPress(keyEvents[u]);
robot.keyRelease(KeyEvent.VK_ALT);
robot.keyRelease(keyEvents[um]);
robot.keyRelease(keyEvents[c]);
robot.keyRelease(keyEvents[d]);
robot.keyRelease(keyEvents[u]);
// Break line
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
//Thread.sleep(100);
}
}
}
}
} catch (AWTException e) {
e.printStackTrace();
}
}
}
I've also found this related queries, but had no luck in finding an answer to my problem:
How to detect Windows alt-code input without relying on keypress?