0

I am developing an Android application that controls the PC keyboard and mouse. I wanted to add a new feature (using your mobile as a game controller). I am using java.awt.Robot. It works fine in controlling the keyboard and mouse. But when I used it with games, java.awt.Robot doesn't press 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 fine in Flash games on the internet, but when I launch a normal game on my PC (like pro evolution soccer), it doesn't work.

Jason Plank
  • 2,336
  • 5
  • 31
  • 40
Hisham Bakr
  • 559
  • 4
  • 13
  • It would be helpful if you provide code from which people can assist you. – ShaneC Sep 19 '11 at 00:20
  • Thanks for advise. I added sample code. – Hisham Bakr Sep 23 '11 at 19:48
  • why no one replied tell now?? is it very difficult ?? – Hisham Bakr Oct 13 '11 at 16:34
  • a lot of days passed and no one answered me. Please if any one knows java.awt.Robot, please try to generate key press inside any full window game (like fifa) and you will understand me. It will not work. but when I used C++. It worked. I want to use Java not C++. – Hisham Bakr Oct 21 '11 at 06:37
  • Thank you all for not assisting me. I managed to fix the issue, published Android app with 100 000 downloads :) – Hisham Bakr Feb 21 '12 at 23:34

2 Answers2

-1

Btw... the problem is that the awt package is not part of Android and you can therefore not use it.

Manfred Moser
  • 29,539
  • 13
  • 92
  • 123
-4

Thank you all for not assisting me. I managed to fix the issue, published Android app with 100000 downloads :)

I was developing an android app that let Android phone control PC and use Android phone as a game controller for PC. I was using TCP and faced thae issue that I cant control games.

When I used UDP instead, the issue fixed. I dont know TCP was the root cause or not but my issue fixed now and my app published on Android market :)

Hisham Bakr
  • 559
  • 4
  • 13