Skip to content

Instantly share code, notes, and snippets.

@hitode909
Created December 24, 2011 08:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hitode909/1516774 to your computer and use it in GitHub Desktop.
Save hitode909/1516774 to your computer and use it in GitHub Desktop.
MouseJump
import java.util.Scanner;
import java.awt.AWTException;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.Robot;
public final class MouseJump
{
public static void main(String[] args) throws AWTException
{
char key;
if (args.length > 0 && args[0].length() > 0) {
key = args[0].charAt(0);
} else {
Scanner stdin = new Scanner(System.in);
key = stdin.nextLine().charAt(0);
}
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
Rectangle window = env.getMaximumWindowBounds();
int splitSizeX = 10;
int splitSizeY = 4;
int inputX = getX(key);
int inputY = getY(key);
double jumpToX = window.width / splitSizeX * (inputX + 0.5);
double jumpToY = window.height / splitSizeY * (inputY + 0.5);
Robot robot = new Robot();
robot.mouseMove((int)Math.round(jumpToX), (int)Math.round(jumpToY));
System.exit(0);
}
public static int getX(char key)
{
switch(key) {
case '1':
case 'q':
case 'a':
case 'z':
return 0;
case '2':
case 'w':
case 's':
case 'x':
return 1;
case '3':
case 'e':
case 'd':
case 'c':
return 2;
case '4':
case 'r':
case 'f':
case 'v':
return 3;
case '5':
case 't':
case 'g':
case 'b':
return 4;
case '6':
case 'y':
case 'h':
case 'n':
return 5;
case '7':
case 'u':
case 'j':
case 'm':
return 6;
case '8':
case 'i':
case 'k':
case ',':
return 7;
case '9':
case 'o':
case 'l':
case '.':
return 8;
case '0':
case 'p':
case ';':
case '/':
return 9;
default:
return 0;
}
}
public static int getY(char key)
{
switch(key) {
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '0':
return 0;
case 'q':
case 'w':
case 'e':
case 'r':
case 't':
case 'y':
case 'u':
case 'i':
case 'o':
case 'p':
return 1;
case 'a':
case 's':
case 'd':
case 'f':
case 'g':
case 'h':
case 'j':
case 'k':
case 'l':
case ';':
return 2;
case 'z':
case 'x':
case 'c':
case 'v':
case 'b':
case 'n':
case 'm':
case ',':
case '.':
case '/':
return 3;
default:
return 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment