MouseEvent Class

https://w3c.github.io/uievents/#mouseevent

public class MouseEvent : UIEvent
Inheritance
UIEvent MouseEvent

Constructors

NameDescription
MouseEvent(string, MouseEventInit?)Creates a mouse event of the given type with the given initialization dictionary.

MouseEvent(string, MouseEventInit?)

UIEvents.cs

Creates a mouse event of the given type with the given initialization dictionary.

public MouseEvent(string type, MouseEventInit? eventInitDict = null)

Properties

NameDescription
AltKeyGets a value indicating whether the Alt key was active.
ButtonGets the button that changed state: 0 for the main button, 1 for the auxiliary button, 2 for the secondary button.
ButtonsGets the bit mask of the buttons that are pressed.
ClientXGets the horizontal coordinate of the pointer relative to the viewport.
ClientYGets the vertical coordinate of the pointer relative to the viewport.
CtrlKeyGets a value indicating whether the Control key was active.
LayerXGets the horizontal coordinate of the pointer relative to the border box of the nearest positioned inclusive ancestor of the target while the event is dispatched (https://w3c.github.io/uievents/#dom-mouseevent-layerx, a legacy attribute), or MouseEvent.PageX.
LayerYGets the vertical coordinate of the pointer relative to the nearest positioned ancestor (https://w3c.github.io/uievents/#dom-mouseevent-layery): see MouseEvent.LayerX.
MetaKeyGets a value indicating whether the Meta key was active.
MovementXGets the horizontal distance of the pointer movement since the previous event.
MovementYGets the vertical distance of the pointer movement since the previous event.
OffsetXGets the horizontal coordinate of the pointer relative to the padding edge of the target while the event is dispatched (https://drafts.csswg.org/cssom-view/#dom-mouseevent-offsetx; the outermost svg element for an element of an SVG document fragment, as in the browsers), or MouseEvent.PageX.
OffsetYGets the vertical coordinate of the pointer relative to the padding edge of the target (https://drafts.csswg.org/cssom-view/#dom-mouseevent-offsety): see MouseEvent.OffsetX.
PageXGets the horizontal coordinate of the pointer relative to the initial containing block (https://drafts.csswg.org/cssom-view/#dom-mouseevent-pagex): MouseEvent.ClientX plus the horizontal scroll position of the window of the event (the window of the realm it was created in, else UIEvent.View).
PageYGets the vertical coordinate of the pointer relative to the initial containing block (https://drafts.csswg.org/cssom-view/#dom-mouseevent-pagey): see MouseEvent.PageX.
RelatedTargetGets the secondary target of the event (for example the element the pointer left), or null.
ScreenXGets the horizontal coordinate of the pointer relative to the screen.
ScreenYGets the vertical coordinate of the pointer relative to the screen.
ShiftKeyGets a value indicating whether the Shift key was active.
XGets the horizontal coordinate of the pointer relative to the viewport (an alias of MouseEvent.ClientX).
YGets the vertical coordinate of the pointer relative to the viewport (an alias of MouseEvent.ClientY).

Gets a value indicating whether the Alt key was active.

public bool AltKey { get; }

Gets the button that changed state: 0 for the main button, 1 for the auxiliary button, 2 for the secondary button.

public short Button { get; }

Gets the bit mask of the buttons that are pressed.

public ushort Buttons { get; }

Gets the horizontal coordinate of the pointer relative to the viewport.

public double ClientX { get; }

Gets the vertical coordinate of the pointer relative to the viewport.

public double ClientY { get; }

Gets a value indicating whether the Control key was active.

public bool CtrlKey { get; }

Gets the horizontal coordinate of the pointer relative to the border box of the nearest positioned inclusive ancestor of the target while the event is dispatched (https://w3c.github.io/uievents/#dom-mouseevent-layerx, a legacy attribute), or MouseEvent.PageX.

public int LayerX { get; }

Gets the vertical coordinate of the pointer relative to the nearest positioned ancestor (https://w3c.github.io/uievents/#dom-mouseevent-layery): see MouseEvent.LayerX.

public int LayerY { get; }

Gets a value indicating whether the Meta key was active.

public bool MetaKey { get; }

MovementX

UIEvents.cs

Gets the horizontal distance of the pointer movement since the previous event.

public double MovementX { get; }

MovementY

UIEvents.cs

Gets the vertical distance of the pointer movement since the previous event.

public double MovementY { get; }

Gets the horizontal coordinate of the pointer relative to the padding edge of the target while the event is dispatched (https://drafts.csswg.org/cssom-view/#dom-mouseevent-offsetx; the outermost svg element for an element of an SVG document fragment, as in the browsers), or MouseEvent.PageX.

public double OffsetX { get; }

Gets the vertical coordinate of the pointer relative to the padding edge of the target (https://drafts.csswg.org/cssom-view/#dom-mouseevent-offsety): see MouseEvent.OffsetX.

public double OffsetY { get; }

Gets the horizontal coordinate of the pointer relative to the initial containing block (https://drafts.csswg.org/cssom-view/#dom-mouseevent-pagex): MouseEvent.ClientX plus the horizontal scroll position of the window of the event (the window of the realm it was created in, else UIEvent.View).

public double PageX { get; }

Gets the vertical coordinate of the pointer relative to the initial containing block (https://drafts.csswg.org/cssom-view/#dom-mouseevent-pagey): see MouseEvent.PageX.

public double PageY { get; }

RelatedTarget

UIEvents.cs

Gets the secondary target of the event (for example the element the pointer left), or null.

public EventTarget? RelatedTarget { get; }

Gets the horizontal coordinate of the pointer relative to the screen.

public double ScreenX { get; }

Gets the vertical coordinate of the pointer relative to the screen.

public double ScreenY { get; }

ShiftKey

UIEvents.cs

Gets a value indicating whether the Shift key was active.

public bool ShiftKey { get; }

Gets the horizontal coordinate of the pointer relative to the viewport (an alias of MouseEvent.ClientX).

public double X { get; }

Gets the vertical coordinate of the pointer relative to the viewport (an alias of MouseEvent.ClientY).

public double Y { get; }

Methods

NameDescription
GetModifierState(string)Returns whether the given modifier key (such as Shift or CapsLock) was active when the event occurred.
InitMouseEvent(string, bool, bool, EventTarget?, int, int, int, int, int, bool, bool, bool, bool, short, EventTarget?)https://w3c.github.io/uievents/#dom-mouseevent-initmouseevent

GetModifierState(string)

UIEvents.cs

Returns whether the given modifier key (such as Shift or CapsLock) was active when the event occurred.

public bool GetModifierState(string keyArg)

InitMouseEvent(string, bool, bool, EventTarget?, int, int, int, int, int, bool, bool, bool, bool, short, EventTarget?)

UIEvents.cs

https://w3c.github.io/uievents/#dom-mouseevent-initmouseevent

public void InitMouseEvent(string typeArg, bool bubblesArg = false, bool cancelableArg = false, EventTarget? viewArg = null, int detailArg = 0, int screenXArg = 0, int screenYArg = 0, int clientXArg = 0, int clientYArg = 0, bool ctrlKeyArg = false, bool altKeyArg = false, bool shiftKeyArg = false, bool metaKeyArg = false, short buttonArg = 0, EventTarget? relatedTargetArg = null)

Parameters

typeArg string
bubblesArg bool
cancelableArg bool
viewArg EventTarget?
detailArg int
screenXArg int
screenYArg int
clientXArg int
clientYArg int
ctrlKeyArg bool
altKeyArg bool
shiftKeyArg bool
metaKeyArg bool
buttonArg short
relatedTargetArg EventTarget?

See also