MousePosition

MousePosition[]

gives the current mouse position in the notebook front end.

MousePosition["coords"]

gives the mouse position with respect to the specified coordinate system.

MousePosition["coords",def]

returns def if the mouse is not over an object that defines the specified coordinate system.

Details

  • Dynamic[MousePosition[]] gives the continually updated current mouse position.
  • MousePosition[{"coords",h}] takes the coordinate system to extend only over the contents of the nearest enclosing object with head h. »
  • The following coordinate systems can be used:
  • "ScreenAbsolute"absolute position within the complete screen display
    "ScreenScaled"scaled position within the complete screen display
    "WindowAbsolute"absolute position down the current window
    "WindowScaled"scaled position down the current window
    "DocumentAbsolute"absolute position down the current complete document
    "DocumentScaled"scaled position down the current complete document
    "CellAbsolute"absolute position within the current cell
    "CellScaled"scaled position within the current cell
    "CellContentsAbsolute"absolute position within the content area of the current cell
    "CellContentsScaled"scaled position within the content area of the current cell
    "EventHandlerAbsolute"absolute position within the current event handler region
    "EventHandlerScaled"scaled position within the current event handler region
    "Graphics"coordinates in the current graphic
    "Graphics3DBoxIntercepts"front and back intercepts with the 3D bounding box
    "GraphicsAbsolute"absolute position within the current graphic
    "GraphicsScaled"scaled position within the current graphic
    "GraphicsImageScaled"scaled position within the current graphics image area
  • Absolute positions are given in printer's points, corresponding to pixels on 72 dpi displays.
  • Scaled positions normally run from 0 to 1 in each direction.
  • For constructs that appear within windows, position {0,0} is taken to be at the bottom left.
  • For complete windows and documents, {0,0} is taken to be at the top left.
  • For the complete screen display, {0,0} is taken to be at the top-left corner of the primary monitor. Secondary monitors correspond to scaled positions outside the range 0 to 1.
  • For "Graphics", ordinary coordinates as specified by PlotRange are used.
  • MousePosition["coords"] is equivalent to MousePosition["coords",None], so that by default None is returned if the mouse is not over an object that defines the specified coordinate system.
  • When used in functions like EventHandler and Button, MousePosition returns the mouse position at the moment when the triggering event occurred.
  • MousePosition["coords"] is equivalent to CurrentValue[{"MousePosition","coords"}].

Examples

open allclose all

Basic Examples  (2)

Get the current position of the mouse:

Get the Dynamic position of the mouse:

Scope  (4)

Get the mouse position in the coordinate system of the graphic:

Get the scaled coordinates of the mouse within the current window:

When the mouse is not within the specified coordinate system, return an expression:

Constrain the coordinate system of MousePosition:

Applications  (1)

Change the color and opacity as the mouse is moved through the graphic:

Properties & Relations  (1)

MousePosition is often used with EventHandler:

Wolfram Research (2007), MousePosition, Wolfram Language function, https://reference.wolfram.com/language/ref/MousePosition.html.

Text

Wolfram Research (2007), MousePosition, Wolfram Language function, https://reference.wolfram.com/language/ref/MousePosition.html.

CMS

Wolfram Language. 2007. "MousePosition." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/MousePosition.html.

APA

Wolfram Language. (2007). MousePosition. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/MousePosition.html

BibTeX

@misc{reference.wolfram_2023_mouseposition, author="Wolfram Research", title="{MousePosition}", year="2007", howpublished="\url{https://reference.wolfram.com/language/ref/MousePosition.html}", note=[Accessed: 19-March-2024 ]}

BibLaTeX

@online{reference.wolfram_2023_mouseposition, organization={Wolfram Research}, title={MousePosition}, year={2007}, url={https://reference.wolfram.com/language/ref/MousePosition.html}, note=[Accessed: 19-March-2024 ]}