Robot

I have been trying to use the Robot class to automatically control a game, but it turns out it works everywhere except inside the game.

I tested a couple of games and the same thing keeps happening. Google wasn’t really helpful on that one, but anyone have any clue why it cant emulate key presses in games?

Here is my code in case you want to have a look. It simply starts a thread and presses the left arrow 10 times.


new Thread(new Runnable(){
			Robot robot = null;
			int i = 0;
			
			@Override
			public void run() {
				
				try {
					robot = new Robot();
				} catch (AWTException e) {
					e.printStackTrace();
				}
				
				while (!stop) {
					try {
						Thread.sleep(1000);
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					System.out.println("wed");
					robot.keyPress(KeyEvent.VK_LEFT);
					robot.keyRelease(KeyEvent.VK_LEFT);
					i++;
					if (i>10) {
						stop = true;
					}
					
				}
			}
			
		}).start();