Mouse Variables


Mouse variables are a special function to return the X and Y position of the mouse cursor when a mouse action takes place.

The position is relative to the meter that has the mouse click or scroll action, or the skin if used in the [Rainmeter] section.

There are two variants of the function.

  • $MouseX$ and $MouseY$
    Contains the current X and Y position of the mouse in pixels relative to the meter or skin.
  • $MouseX:%$ and $MouseY:%$
    Contains the current X and Y position of the mouse as a percentage relative to the meter or skin.

Usage

The variables are only created and used in the context of a mouse click or scroll action. Primarily, they will be used as a parameter to a Bang. For instance:

LeftMouseUpAction=[!SetOption SomeMeter X $MouseX$][!UpdateMeter *][!Redraw]

LeftMouseUpAction=!CommandMeasure ScriptMeasure GetRGB($MouseX$,$MouseY$)

Notes: The values returned are not the mouse position on the screen, but are pixels or a percentage relative to the meter or skin with the mouse action. They are also not general purpose variables, and when used outside the context of a mouse action on a meter or the skin, will not contain a value.

$MouseX$

X position of the mouse cursor as a number of pixels relative to the meter or skin with the mouse action.

$MouseY$

Y position of the mouse cursor as a number of pixels relative to the meter or skin with the mouse action.

$MouseX:%$

X position of the mouse cursor as a percentage relative to the meter or skin with the mouse action.

$MouseY:%$

Y position of the mouse cursor as a percentage relative to the meter or skin with the mouse action.

Example

[Rainmeter]
LeftMouseUpAction=[!SetOptionGroup Coordinates Text "Click the square!"][!UpdateMeterGroup Coordinates][!Redraw]

[Background]
Meter=Image
SolidColor=0,0,150
W=150
H=225

[CoordinateA]
Meter=String
FontColor=255,255,255
Text=Click the square!
Group=Coordinates

[RedSquare]
Meter=Image
SolidColor=255,0,0
X=25
Y=30
W=100
H=100
LeftMouseUpAction=[!SetOption CoordinateA Text "($MouseX$, $MouseY$)"][!UpdateMeter CoordinateA][!Redraw]
MouseActionCursorName=Cross

[CoordinateB]
Meter=String
FontColor=255,255,255
Text=Click the square!
Group=Coordinates
Y=20R

[GreenSquare]
Meter=Image
SolidColor=0,255,0
X=25
Y=180
W=100
H=25
LeftMouseUpAction=[!SetOption CoordinateB Text "X = $MouseX:%$%, Y = $MouseY:%$%"][!UpdateMeter CoordinateB][!Redraw]
MouseActionCursorName=Cross