files/en-us/web/api/mouseevent/index.md
{{APIRef("Pointer Events")}}
The MouseEvent interface represents events that occur due to the user interacting with a pointing device (such as a mouse).
Common events using this interface include {{domxref("Element/click_event", "click")}}, {{domxref("Element/dblclick_event", "dblclick")}}, {{domxref("Element/mouseup_event", "mouseup")}}, {{domxref("Element/mousedown_event", "mousedown")}}.
MouseEvent derives from {{domxref("UIEvent")}}, which in turn derives from {{domxref("Event")}}.
Though the {{domxref("MouseEvent.initMouseEvent()")}} method is kept for backward compatibility, creating of a MouseEvent object should be done using the {{domxref("MouseEvent.MouseEvent", "MouseEvent()")}} constructor.
Several more specific events are based on MouseEvent, including {{domxref("WheelEvent")}}, {{domxref("DragEvent")}}, and {{domxref("PointerEvent")}}.
{{InheritanceDiagram}}
MouseEvent object.This interface also inherits properties of its parents, {{domxref("UIEvent")}} and {{domxref("Event")}}.
true if the <kbd>alt</kbd> key was down when the mouse event was fired.true if the <kbd>control</kbd> key was down when the mouse event was fired.true if the <kbd>meta</kbd> key was down when the mouse event was fired.true if the <kbd>shift</kbd> key was down when the mouse event was fired.MOZ_SOURCE_* constants).
This lets you, for example, determine whether a mouse event was generated by an actual mouse or by a touch event (which might affect the degree of accuracy with which you interpret the coordinates associated with the event).This interface also inherits methods of its parents, {{domxref("UIEvent")}} and {{domxref("Event")}}.
MouseEvent created. If the event has already been dispatched, this method does nothing.This example demonstrates simulating a click (programmatically generating a click event) on a checkbox using DOM methods. Event state (canceled or not) is then determined with the return value of method {{domxref("EventTarget.dispatchEvent", "EventTarget.dispatchEvent()")}}.
<p>
<label><input type="checkbox" id="checkbox" /> Checked</label>
</p>
<p>
<button id="button">Click me to send a MouseEvent to the checkbox</button>
</p>
function simulateClick() {
// Get the element to send a click event
const cb = document.getElementById("checkbox");
// Create a synthetic click MouseEvent
let evt = new MouseEvent("click", {
bubbles: true,
cancelable: true,
view: window,
});
// Send the event to the checkbox element
cb.dispatchEvent(evt);
}
document.getElementById("button").addEventListener("click", simulateClick);
{{EmbedLiveSample('Example')}}
{{Specifications}}
{{Compat}}