-
June 26th, 2011, 10:19 PM
#1
[RESOLVED] Java
Hi all, I am trying to automate a process in a first person shooter game, basically:
While holding space bar down,
when I move the mouse right, I would like to have key1 held down,
when I move the mouse left, I would like to have key2 held down.
With my very little knowledge of java and great knowledge of google, I have come up with this partial solution:
I'm just skipping the "while the spacebar is held down" for now.
Now, this program works perfectly in windows. However when I launch this DirectX game, the FPS game seems to report that the mouse is always in the dead centre of the screen, when I move the mouse left, the program only realises this for very very short periods (like 5ms) before the game seems to reset the mouse position back to centre.
I am wondering if there is some other way that I could use java to work out if the mouse is "attempting to" move left or right while in the game so that I get more consistent results ingame.
Here is what I have managed to come up with so far:
Code:
import java.awt.MouseInfo;
import java.awt.Robot;
import java.awt.event.KeyEvent;
public class bhop {
public static void main(String[] args) throws Exception{
while(true){
// Get mouse position, wait 25 ticks, get it again
int xPos1 = MouseInfo.getPointerInfo().getLocation().x;
Thread.sleep(25);
int xPos2 = MouseInfo.getPointerInfo().getLocation().x;
Robot RobotOne = new Robot();
// If the 2nd value is higher than the first, mouse is moving left
// Press & Hold "A"
if (xPos1 > xPos2) {
RobotOne.keyPress( KeyEvent.VK_A );
Thread.sleep(25);
// Else If the 2nd value is higher than the first, mouse is moving right
// Press & Hold "D"
} else if (xPos1 < xPos2) {
System.out.println("right");
RobotOne.keyPress( KeyEvent.VK_D );
Thread.sleep(25);
}
}
}
}
All comments and suggestions are greatly appreciated.
-
June 27th, 2011, 05:40 AM
#2
Re: [RESOLVED] Java
sorry for the double-post, please ignore this one
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|