Skip to content

Commit

Permalink
prep 2.0.1 and polish SystemDiagnosis class a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
JoonasVali committed Apr 28, 2019
1 parent e82534a commit 9704cfa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.joonasvali.naturalmouse</groupId>
<artifactId>naturalmouse</artifactId>
<version>2.0.1-SNAPSHOT</version>
<version>2.0.1</version>
<name>Natural Mouse Motion</name>
<url>https://github.com/JoonasVali/NaturalMouseMotion</url>
<description>This library provides a way to move cursor to specified coordinates on screen reliably,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@

public class SystemDiagnosis {

public static void main(String[] args) {
new SystemDiagnosis().validateMouseMovement();
}

public void validateMouseMovement() {
/**
* Runs a diagnosis with default configuration, by setting mouse all over your screen and expecting to receive
* correct coordinates back.
* If java.awt.Robot cannot be constructed, then new RuntimeException is thrown.
* If no issues are found, then this method completes without throwing an error, otherwise IllegalStateException is
* thrown.
*/
public static void validateMouseMovement() {
try {
Robot robot = new Robot();
validateMouseMovement(new DefaultSystemCalls(robot), new DefaultMouseInfoAccessor());
Expand All @@ -22,7 +25,14 @@ public void validateMouseMovement() {
}
}

public void validateMouseMovement(SystemCalls system, MouseInfoAccessor accessor) {
/**
* Runs a diagnosis, by setting mouse all over your screen and expecting to receive correct coordinates back.
* If no issues are found, then this method completes without throwing an error, otherwise IllegalStateException is
* thrown.
* @param system a SystemCalls class which is used for setting the mouse position
* @param accessor a MouseInfoAccessor which is used for querying mouse position
*/
public static void validateMouseMovement(SystemCalls system, MouseInfoAccessor accessor) {
Dimension dimension = system.getScreenSize();
for (int y = 0; y < dimension.height; y += 50) {
for (int x = 0; x < dimension.width; x += 50) {
Expand All @@ -36,7 +46,7 @@ public void validateMouseMovement(SystemCalls system, MouseInfoAccessor accessor

Point p = accessor.getMousePosition();
if (x != p.x || y != p.y) {
throw new IllegalArgumentException(
throw new IllegalStateException(
"Tried to move mouse to (" + x + ", " + y + "). Actually moved to (" + p.x + ", " + p.y + ")" +
"This means NaturalMouseMotion is not able to work optimally on this system as the cursor move " +
"calls may miss the target pixels on the screen."
Expand Down

0 comments on commit 9704cfa

Please sign in to comment.