public interface MouseEvent extends UIEvent
MouseEvent
interface provides specific contextual
information associated with Mouse events.
In the case of nested elements mouse events are always targeted at the most deeply nested element. Ancestors of the targeted element may use bubbling to obtain notification of mouse events which occur within theirs descendent elements.
To create an instance of the MouseEvent
interface, use the
DocumentEvent.createEvent("MouseEvent")
method call.
Note: When initializing MouseEvent
objects using
initMouseEvent
or initMouseEventNS
,
implementations should use the client coordinates clientX
and clientY
for calculation of other coordinates (such as
target coordinates exposed by DOM Level 0 implementations).
See also the Document Object Model (DOM) Level 3 Events Specification.
AT_TARGET, BUBBLING_PHASE, CAPTURING_PHASE
Modifier and Type | Method and Description |
---|---|
boolean |
getAltKey()
true if the alt (alternative) key modifier is activated. |
short |
getButton()
During mouse events caused by the depression or release of a mouse
button,
button is used to indicate which mouse button
changed state. |
int |
getClientX()
The horizontal coordinate at which the event occurred relative to the
DOM implementation's client area.
|
int |
getClientY()
The vertical coordinate at which the event occurred relative to the
DOM implementation's client area.
|
boolean |
getCtrlKey()
true if the control (Ctrl) key modifier is activated. |
boolean |
getMetaKey()
true if the meta (Meta) key modifier is activated. |
EventTarget |
getRelatedTarget()
Used to identify a secondary
EventTarget related to a UI
event, depending on the type of event. |
int |
getScreenX()
The horizontal coordinate at which the event occurred relative to the
origin of the screen coordinate system.
|
int |
getScreenY()
The vertical coordinate at which the event occurred relative to the
origin of the screen coordinate system.
|
boolean |
getShiftKey()
true if the shift (Shift) key modifier is activated. |
void |
initMouseEvent(String typeArg,
boolean canBubbleArg,
boolean cancelableArg,
AbstractView viewArg,
int detailArg,
int screenXArg,
int screenYArg,
int clientXArg,
int clientYArg,
boolean ctrlKeyArg,
boolean altKeyArg,
boolean shiftKeyArg,
boolean metaKeyArg,
short buttonArg,
EventTarget relatedTargetArg)
The
initMouseEvent method is used to initialize the value
of a MouseEvent object and has the same behavior as
UIEvent.initUIEvent() . |
void |
initMouseEventNS(String namespaceURI,
String typeArg,
boolean canBubbleArg,
boolean cancelableArg,
AbstractView viewArg,
int detailArg,
int screenXArg,
int screenYArg,
int clientXArg,
int clientYArg,
short buttonArg,
EventTarget relatedTargetArg,
String modifiersList)
The
initMouseEventNS method is used to initialize the
value of a MouseEvent object and has the same behavior
as UIEvent.initUIEventNS() . |
getDetail, getView, initUIEvent, initUIEventNS
getBubbles, getCancelable, getCurrentTarget, getDefaultPrevented, getEventPhase, getNamespaceURI, getTarget, getTimeStamp, getType, initEvent, initEventNS, preventDefault, stopPropagation
int getScreenX()
int getScreenY()
int getClientX()
int getClientY()
boolean getCtrlKey()
true
if the control (Ctrl) key modifier is activated.boolean getShiftKey()
true
if the shift (Shift) key modifier is activated.boolean getAltKey()
true
if the alt (alternative) key modifier is activated.
Note: The Option key modifier on Macintosh systems must be represented using this key modifier.
boolean getMetaKey()
true
if the meta (Meta) key modifier is activated.
Note: The Command key modifier on Macintosh system must be represented using this meta key.
short getButton()
button
is used to indicate which mouse button
changed state. 0
indicates the normal button of the
mouse (in general on the left or the one button on Macintosh mice,
used to activate a button or select text). 2
indicates
the contextual property (in general on the right, used to display a
context menu) button of the mouse if present. 1
indicates the extra (in general in the middle and often combined with
the mouse wheel) button. Some mice may provide or simulate more
buttons, and values higher than 2
can be used to
represent such buttons.EventTarget getRelatedTarget()
EventTarget
related to a UI
event, depending on the type of event.void initMouseEvent(String typeArg, boolean canBubbleArg, boolean cancelableArg, AbstractView viewArg, int detailArg, int screenXArg, int screenYArg, int clientXArg, int clientYArg, boolean ctrlKeyArg, boolean altKeyArg, boolean shiftKeyArg, boolean metaKeyArg, short buttonArg, EventTarget relatedTargetArg)
initMouseEvent
method is used to initialize the value
of a MouseEvent
object and has the same behavior as
UIEvent.initUIEvent()
.typeArg
- Refer to the UIEvent.initUIEvent()
method
for a description of this parameter.canBubbleArg
- Refer to the UIEvent.initUIEvent()
method for a description of this parameter.cancelableArg
- Refer to the UIEvent.initUIEvent()
method for a description of this parameter.viewArg
- Refer to the UIEvent.initUIEvent()
method
for a description of this parameter.detailArg
- Refer to the UIEvent.initUIEvent()
method for a description of this parameter.screenXArg
- Specifies MouseEvent.screenX
.screenYArg
- Specifies MouseEvent.screenY
.clientXArg
- Specifies MouseEvent.clientX
.clientYArg
- Specifies MouseEvent.clientY
.ctrlKeyArg
- Specifies MouseEvent.ctrlKey
.altKeyArg
- Specifies MouseEvent.altKey
.shiftKeyArg
- Specifies MouseEvent.shiftKey
.metaKeyArg
- Specifies MouseEvent.metaKey
.buttonArg
- Specifies MouseEvent.button
.relatedTargetArg
- Specifies
MouseEvent.relatedTarget
. This value may be
null
.void initMouseEventNS(String namespaceURI, String typeArg, boolean canBubbleArg, boolean cancelableArg, AbstractView viewArg, int detailArg, int screenXArg, int screenYArg, int clientXArg, int clientYArg, short buttonArg, EventTarget relatedTargetArg, String modifiersList)
initMouseEventNS
method is used to initialize the
value of a MouseEvent
object and has the same behavior
as UIEvent.initUIEventNS()
.namespaceURI
- Refer to the UIEvent.initUIEventNS()
method for a description of this parameter.typeArg
- Refer to the UIEvent.initUIEventNS()
method for a description of this parameter.canBubbleArg
- Refer to the UIEvent.initUIEventNS()
method for a description of this parameter.cancelableArg
- Refer to the UIEvent.initUIEventNS()
method for a description of this parameter.viewArg
- Refer to the UIEvent.initUIEventNS()
method for a description of this parameter.detailArg
- Refer to the UIEvent.initUIEventNS()
method for a description of this parameter.screenXArg
- Refer to the
MouseEvent.initMouseEvent()
method for a description
of this parameter.screenYArg
- Refer to the
MouseEvent.initMouseEvent()
method for a description
of this parameter.clientXArg
- Refer to the
MouseEvent.initMouseEvent()
method for a description
of this parameter.clientYArg
- Refer to the
MouseEvent.initMouseEvent()
method for a description
of this parameter.buttonArg
- Refer to the MouseEvent.initMouseEvent()
method for a description of this parameter.relatedTargetArg
- Refer to the
MouseEvent.initMouseEvent()
method for a description
of this parameter.modifiersList
- A
white space separated list of modifier key identifiers to be
activated on this object. As an example, "Control Alt"
will activated the control and alt modifiers.