Function Repository Resource:

MoveMouse

Source Notebook

Move the mouse cursor to a specified location

Contributed by: Richard Hennigan (Wolfram Research)

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

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

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

is equivalent to ResourceFunction["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 ResourceFunction["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
{action1,action2,}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.0how long it takes for the cursor to reach its destination
"SelectNotebook"Truewhether or not to select the given notebook first

Examples

Basic Examples (2) 

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[5]=
In[6]:=
NotebookClose[notebook]

Scope (3) 

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 (3) 

Delay (2) 

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 (1) 

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[9]=
In[14]:=
NotebookClose[notebook]

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 2.0.0 – 30 December 2019
  • 1.0.0 – 17 August 2018

Related Resources

License Information