How can I use java.awt.Robot inside games?

I am developing an Android application that controls the keyboard and mouse of a PC. I wanted to add a new feature (using your mobile as a game controller). I am using java.awt.Robot

. It works great with keyboard and mouse control. But when i used it with games it java.awt.Robot

doesn't click buttons. When I go outside the game, it works fine again.

For example:

if (senderPropertyOne.equalsIgnoreCase("l")) {
    robot.keyPress(KeyEvent.VK_LEFT);
    robot.keyRelease(KeyEvent.VK_LEFT);
} else if (senderPropertyOne.equalsIgnoreCase("r")) {
    robot.keyPress(KeyEvent.VK_RIGHT);
    robot.keyRelease(KeyEvent.VK_RIGHT);
} else if (senderPropertyOne.equalsIgnoreCase("u")) {
    robot.keyPress(KeyEvent.VK_UP));        
    robot.keyRelease(KeyEvent.VK_UP);
} else if (senderPropertyOne.equalsIgnoreCase("d")) {
   robot.keyPress(KeyEvent.VK_DOWN);
   robot.keyRelease(KeyEvent.VK_DOWN);

      

This works great on internet flash games, but when I run a normal game on my PC (like Evolution Football) it doesn't work.

+1


source to share


2 answers


Thanks for not helping me. I was able to fix this issue, published Android app with 100,000 downloads :)

I was developing an Android app that allowed an Android phone to control a PC and use an Android phone as a PC game controller. I was using TCP and ran into an issue that I cannot control.



When I used UDP instead, the problem was fixed. I don't know if TCP was the root cause or not, but my problem has been fixed and my app is published on the Android market :)

-4


source


Btw ... the problem is the awt package is not part of Android, so you cannot use it.



-1


source







All Articles