Skip to main content
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

I need to automate mouse clicks with Mathematica. However, a similiar questionsimiliar question was closed on this forum, without any answer.

Consider the following steps:

 Dynamic[MousePosition[]]

In this first step I dynamically show the mouse position.

 DynamicModule[{col = Green}, EventHandler[ Style["text", FontColor -> 
 Dynamic[col]], {"MouseClicked" :> (col = col /. {Red -> Green, Green -> Red})}]]

In this second step I create a "clickable" text: when you click it, it changes its color between green and red.

My objective here is twofold:

1) automatically move the cursor position - this has already been answered herehere. So, following the original answer I can write

Needs["JLink`"];
ReinstallJava[];
robotclass = JavaNew["java.awt.Robot"];
robotclass@mouseMove[90, 196];

2) automatically click on the clickable text (and, of course, I want to see its color changing). Here is the code I'm trying to use:

robotclass@mousePress[InputEvent.BUTTON1_MASK];
robotclass@mouseRelease[InputEvent.BUTTON1_MASK];

Although I believe I'm using the correct functions (which belong to the Java Robot Class), I'm getting the following error message:

Java::argx1: Method named mouseRelease defined in class java.awt.Robot was called with an incorrect number or type of arguments. The argument was InputEvent.BUTTON1_MASK.

Can anybody give me a hint to solve this problem?

I need to automate mouse clicks with Mathematica. However, a similiar question was closed on this forum, without any answer.

Consider the following steps:

 Dynamic[MousePosition[]]

In this first step I dynamically show the mouse position.

 DynamicModule[{col = Green}, EventHandler[ Style["text", FontColor -> 
 Dynamic[col]], {"MouseClicked" :> (col = col /. {Red -> Green, Green -> Red})}]]

In this second step I create a "clickable" text: when you click it, it changes its color between green and red.

My objective here is twofold:

1) automatically move the cursor position - this has already been answered here. So, following the original answer I can write

Needs["JLink`"];
ReinstallJava[];
robotclass = JavaNew["java.awt.Robot"];
robotclass@mouseMove[90, 196];

2) automatically click on the clickable text (and, of course, I want to see its color changing). Here is the code I'm trying to use:

robotclass@mousePress[InputEvent.BUTTON1_MASK];
robotclass@mouseRelease[InputEvent.BUTTON1_MASK];

Although I believe I'm using the correct functions (which belong to the Java Robot Class), I'm getting the following error message:

Java::argx1: Method named mouseRelease defined in class java.awt.Robot was called with an incorrect number or type of arguments. The argument was InputEvent.BUTTON1_MASK.

Can anybody give me a hint to solve this problem?

I need to automate mouse clicks with Mathematica. However, a similiar question was closed on this forum, without any answer.

Consider the following steps:

 Dynamic[MousePosition[]]

In this first step I dynamically show the mouse position.

 DynamicModule[{col = Green}, EventHandler[ Style["text", FontColor -> 
 Dynamic[col]], {"MouseClicked" :> (col = col /. {Red -> Green, Green -> Red})}]]

In this second step I create a "clickable" text: when you click it, it changes its color between green and red.

My objective here is twofold:

1) automatically move the cursor position - this has already been answered here. So, following the original answer I can write

Needs["JLink`"];
ReinstallJava[];
robotclass = JavaNew["java.awt.Robot"];
robotclass@mouseMove[90, 196];

2) automatically click on the clickable text (and, of course, I want to see its color changing). Here is the code I'm trying to use:

robotclass@mousePress[InputEvent.BUTTON1_MASK];
robotclass@mouseRelease[InputEvent.BUTTON1_MASK];

Although I believe I'm using the correct functions (which belong to the Java Robot Class), I'm getting the following error message:

Java::argx1: Method named mouseRelease defined in class java.awt.Robot was called with an incorrect number or type of arguments. The argument was InputEvent.BUTTON1_MASK.

Can anybody give me a hint to solve this problem?

Source Link
Rod
  • 3.3k
  • 2
  • 25
  • 41

Automate mouse clicks with Mathematica

I need to automate mouse clicks with Mathematica. However, a similiar question was closed on this forum, without any answer.

Consider the following steps:

 Dynamic[MousePosition[]]

In this first step I dynamically show the mouse position.

 DynamicModule[{col = Green}, EventHandler[ Style["text", FontColor -> 
 Dynamic[col]], {"MouseClicked" :> (col = col /. {Red -> Green, Green -> Red})}]]

In this second step I create a "clickable" text: when you click it, it changes its color between green and red.

My objective here is twofold:

1) automatically move the cursor position - this has already been answered here. So, following the original answer I can write

Needs["JLink`"];
ReinstallJava[];
robotclass = JavaNew["java.awt.Robot"];
robotclass@mouseMove[90, 196];

2) automatically click on the clickable text (and, of course, I want to see its color changing). Here is the code I'm trying to use:

robotclass@mousePress[InputEvent.BUTTON1_MASK];
robotclass@mouseRelease[InputEvent.BUTTON1_MASK];

Although I believe I'm using the correct functions (which belong to the Java Robot Class), I'm getting the following error message:

Java::argx1: Method named mouseRelease defined in class java.awt.Robot was called with an incorrect number or type of arguments. The argument was InputEvent.BUTTON1_MASK.

Can anybody give me a hint to solve this problem?