Wolfram Computation Meets Knowledge

MoveMouse

Contributed by: Richard Hennigan (Wolfram Research)

Moves the mouse cursor to a specified location

ResourceFunction["MoveMouse"][{x,y}]

moves the mouse cursor to the screen coordinates (x,y).

ResourceFunction["MoveMouse"][All,{x,y}]

is equivalent to MoveMouse[{x,y}].

ResourceFunction["MoveMouse"][notebook,{x,y}]

moves the mouse cursor to the coordinates (x,y) using the position of notebook as the offset.

ResourceFunction["MoveMouse"][scope,{x,y},actions]

performs actions after moving the cursor.

Details and Options

In MoveMouse[scope,{x,y},actions],actions can be any of the following:
"Click" click the left mouse button
"Wait" wait one second
{"Type", string} simulate typing the text given in string
{ action 1 , action 2 , } a list of actions
Additionally, each action can accept additional parameters by including them in a list:
{"Click",delay} wait for delay seconds before clicking
{"Wait",delay} wait for delay seconds
{"Type",delay,string} pause for delay seconds between each keystroke
MouseMove accepts the following options:
"Delay" 1.0 how long it takes for the cursor to reach its destination
"SelectNotebook" True whether or not to select the given notebook first

Examples

Basic Examples

Move the mouse to specific screen coordinates:

In[1]:=
ResourceFunction["MoveMouse"][{100, 200}]
MousePosition["ScreenAbsolute"]
Out[2]=

Move the mouse to relative coordinates in a notebook:

In[3]:=
notebook = CreateWindow[WindowFrame -> "Frameless", WindowElements -> {}];
ResourceFunction["MoveMouse"][notebook, {25, 50}]
MousePosition["WindowAbsolute"]
Out[4]=
In[5]:=
NotebookClose[notebook]

More Examples

Scope

Retrieve the ResourceFunction:

In[6]:=
ResourceFunction["MoveMouse"]
Out[6]=

Move the mouse to a specified location and then click the left mouse button:

In[7]:=
notebook = CreateWindow[
   WindowSize -> {1000, 400},
   NotebookEventActions -> {
     "MouseClicked" :> SetOptions[SelectedNotebook[], Background -> Pink]
     }
   ];
ResourceFunction["MoveMouse"][notebook, {200, 200}, "Click"]

Move the mouse to a specified location, click, and then type some text:

In[8]:=
ResourceFunction[
 "MoveMouse"][notebook, {100, 100}, {"Click", {"Type", "f[x_]:=x+1\[IndentingNewLine]"}}]

Increase the delay between keystrokes:

In[9]:=
ResourceFunction[
 "MoveMouse"][notebook, {100, 200}, {"Click", {"Type", 0.25, "\"This will be typed much slower\""}}]
In[10]:=
NotebookClose[notebook]

Options

Delay

By default, the mouse movement is smooth with one second of travel time. Set "Delay" to 0 to move instantly:

In[11]:=
ResourceFunction["MoveMouse"][{0, 0}, "Delay" -> 0]

Move the cursor smoothly over five seconds:

In[12]:=
ResourceFunction["MoveMouse"][{1500, 1000}, "Delay" -> 5]
SelectNotebook

Set "SelectNotebook" to False to prevent the given notebook from being selected:

In[13]:=
notebook = CreateWindow[];
SetSelectedNotebook[EvaluationNotebook[]];
ResourceFunction["MoveMouse"][notebook, {200, 200}, "SelectNotebook" -> False]
SelectedNotebook[] === EvaluationNotebook[]
Out[14]=
In[15]:=
NotebookClose[notebook]

Properties and Relations

Retrieve the ResourceObject:

In[16]:=
ResourceObject["MoveMouse"]
Out[16]=

Resource History