import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.Robot;
public class Main extends JFrame implements KeyListener {
public Main() throws AWTException {
setSize(100,100);
setVisible(true);
addKeyListener(this);
}
public static void main(String[] args) throws AWTException {
Main f = new Main();
}
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
try {
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_7);
robot.keyRelease(KeyEvent.VK_7);
} catch (AWTException ex) {
ex.printStackTrace();
}
}
}
@Override
public void keyReleased(KeyEvent e) {
}
}
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.Robot;
public class Main extends JFrame implements KeyListener {
public Main() throws AWTException {
setSize(100,100);
setVisible(true);
addKeyListener(this);
}
public static void main(String[] args) throws AWTException {
Main f = new Main();
}
@Override
public void keyTyped(KeyEvent e) {
}
Robot robot = new Robot();
@Override
public void keyPressed(KeyEvent e) {
if(e.getKeyCode()== KeyEvent.VK_RIGHT){
robot.keyPress(KeyEvent.VK_7);
}
}
@Override
public void keyReleased(KeyEvent e) {
}
}
при нажатии стрелки в право должно печататься 7 почему этого не происходит ?