Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package test;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.JFrame;
- /**
- *
- * @author kajacx
- */
- public class RobotArrow {
- public static void main(String[] args) throws InterruptedException, AWTException {
- JFrame f = new JFrame("TEST");
- f.setSize(200, 200);
- f.setLocationRelativeTo(null);
- f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- f.setVisible(true);
- KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
- manager.addKeyEventDispatcher(new KeyEventDispatcher() {
- @Override
- public boolean dispatchKeyEvent(KeyEvent e) {
- if (e.getID() == KeyEvent.KEY_PRESSED) {
- System.out.format("code: %d, location: %d\n",
- e.getKeyCode(), e.getKeyLocation());
- }
- return false;
- }
- });
- Thread.sleep(1000);
- Robot bot = new Robot();
- bot.keyPress(KeyEvent.VK_UP);
- bot.keyRelease(KeyEvent.VK_UP);
- bot.keyPress(KeyEvent.VK_KP_UP);
- bot.keyRelease(KeyEvent.VK_KP_UP);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement