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.

DetailsDetails

  • 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 is taken to be at the bottom left.
  • For complete windows and documents, is taken to be at the top left.
  • For the complete screen display, 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 , 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"}].
Introduced in 2007
(6.0)