I am trying to code a small module that allows user to enter a key by others keys (Key mapping) using NativeKeyListener
. Mapping function is working fine but output always has 2 keys value (one is the key you press,one is mapped key). I only want mapped key value is entered.
This is my code:
public void nativeKeyPressed(NativeKeyEvent e) {
String keyText = NativeKeyEvent.getKeyText(e.getKeyCode());
if (keyText.equals("B")) {
try {
robot = new Robot();
robot.setAutoDelay(0);
robot.keyPress(103);
} catch (AWTException ex) {
ex.printStackTrace();
}
} else if (keyText.equals("N")) {
try {
robot = new Robot();
robot.setAutoDelay(0);
robot.keyPress(104);
} catch (AWTException ex) {
ex.printStackTrace();
}
}
Reality Output:
When I press "B": -> b7.
When I press "N". -> n8.
Expected Output:
When I press "B": -> 7.
When I press "N". -> 8.