--- title: MouseEvent slug: Web/API/MouseEvent translation_of: Web/API/MouseEvent ---
{{APIRef("DOM Events")}}

MouseEvent 인터페이스는 특정 지점을 가리키는 장치를 통해 발생하는 이벤트를 의미한다 (마우스 등). 주로 사용되는 이벤트로는 {{event("click")}}, {{event("dblclick")}}, {{event("mouseup")}}, {{event("mousedown")}}가 있다.

MouseEvent 는 {{domxref("UIEvent")}}에서, {{domxref("UIEvent")}}는 {{domxref("Event")}}에서 파생되었다. MouseEvent 객체(object)를 생성하고자 할 때에는 {{domxref("MouseEvent.MouseEvent", "MouseEvent()")}} 생성자(constructor)를 사용해야 한다. {{domxref("MouseEvent.initMouseEvent()")}} 메서드는 하위호환성을 위해 유지된다.

{{domxref("WheelEvent")}}, {{domxref("DragEvent")}} 등 특정 이벤트는 MouseEvent를 기반으로 한다.

{{InheritanceDiagram}}

Constructor

{{domxref("MouseEvent.MouseEvent", "MouseEvent()")}}
Creates a MouseEvent object.

Properties

This interface also inherits properties of its parents, {{domxref("UIEvent")}} and {{domxref("Event")}}.

{{domxref("MouseEvent.altKey")}} {{readonlyinline}}
Returns true if the alt key was down when the mouse event was fired.
{{domxref("MouseEvent.button")}} {{readonlyinline}}
The button number that was pressed (if applicable) when the mouse event was fired.
{{domxref("MouseEvent.buttons")}} {{readonlyinline}} {{gecko_minversion_inline("15.0")}}
The buttons being depressed (if any) when the mouse event was fired.
{{domxref("MouseEvent.clientX")}} {{readonlyinline}}
The X coordinate of the mouse pointer in local (DOM content) coordinates.
{{domxref("MouseEvent.clientY")}} {{readonlyinline}}
The Y coordinate of the mouse pointer in local (DOM content) coordinates.
{{domxref("MouseEvent.ctrlKey")}} {{readonlyinline}}
Returns true if the control key was down when the mouse event was fired.
{{domxref("MouseEvent.metaKey")}} {{readonlyinline}}
Returns true if the meta key was down when the mouse event was fired.
{{domxref("MouseEvent.movementX")}} {{readonlyinline}}
The X coordinate of the mouse pointer relative to the position of the last {{event("mousemove")}} event.
{{domxref("MouseEvent.movementY")}} {{readonlyinline}}
The Y coordinate of the mouse pointer relative to the position of the last {{event("mousemove")}} event.
{{domxref("MouseEvent.offsetX")}} {{readonlyinline}}{{experimental_inline}}
The X coordinate of the mouse pointer relative to the position of the padding edge of the target node.
{{domxref("MouseEvent.offsetY")}} {{readonlyinline}}{{experimental_inline}}
The Y coordinate of the mouse pointer relative to the position of the padding edge of the target node.
{{domxref("MouseEvent.pageX")}} {{readonlyinline}}{{experimental_inline}}
The X coordinate of the mouse pointer relative to the whole document.
{{domxref("MouseEvent.pageY")}} {{readonlyinline}}{{experimental_inline}}
The Y coordinate of the mouse pointer relative to the whole document.
{{domxref("MouseEvent.region")}} {{readonlyinline}}
Returns the id of the hit region affected by the event. If no hit region is affected, null is returned.
{{domxref("MouseEvent.relatedTarget")}} {{readonlyinline}}

The secondary target for the event, if there is one.

{{domxref("MouseEvent.screenX")}} {{readonlyinline}}
The X coordinate of the mouse pointer in global (screen) coordinates.
{{domxref("MouseEvent.screenY")}} {{readonlyinline}}
The Y coordinate of the mouse pointer in global (screen) coordinates.
{{domxref("MouseEvent.shiftKey")}} {{readonlyinline}}
Returns true if the shift key was down when the mouse event was fired.
{{domxref("MouseEvent.which")}} {{non-standard_inline}} {{readonlyinline}}
The button being pressed when the mouse event was fired.
{{domxref("MouseEvent.mozPressure")}} {{non-standard_inline()}} {{deprecated_inline}} {{readonlyinline}}
The amount of pressure applied to a touch or tablet device when generating the event; this value ranges between 0.0 (minimum pressure) and 1.0 (maximum pressure). Instead of using this deprecated (and non-standard) property, you should instead use {{domxref("PointerEvent")}} and look at its {{domxref("PointerEvent.pressure", "pressure")}} property.
{{domxref("MouseEvent.mozInputSource")}} {{non-standard_inline()}} {{readonlyinline}}
The type of device that generated the event (one of the MOZ_SOURCE_* constants listed below). 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).
{{domxref("MouseEvent.webkitForce")}} {{non-standard_inline()}} {{readonlyinline}}
The amount of pressure applied when clicking
{{domxref("MouseEvent.x")}} {{experimental_inline}}{{readonlyinline}}
Alias for {{domxref("MouseEvent.clientX")}}.
{{domxref("MouseEvent.y")}} {{experimental_inline}}{{readonlyinline}}
Alias for {{domxref("MouseEvent.clientY")}}

Constants

{{domxref("MouseEvent.WEBKIT_FORCE_AT_MOUSE_DOWN")}} {{non-standard_inline}}{{readonlyinline}}
Minimum force necessary for a normal click
{{domxref("MouseEvent.WEBKIT_FORCE_AT_FORCE_MOUSE_DOWN")}} {{non-standard_inline}}{{readonlyinline}}
Minimum force necessary for a force click

Methods

This interface also inherits methods of its parents, {{domxref("UIEvent")}} and {{domxref("Event")}}.

{{domxref("MouseEvent.getModifierState()")}}
Returns the current state of the specified modifier key. See the {{domxref("KeyboardEvent.getModifierState")}}() for details.
{{domxref("MouseEvent.initMouseEvent()")}} {{deprecated_inline}}
Initializes the value of a MouseEvent created. If the event has already being dispatched, this method does nothing.

Example

This example demonstrates simulating a click (that is programmatically generating a click event) on a checkbox using DOM methods.

HTML

<p><label><input type="checkbox" id="checkbox"> Checked</label>
<p><button id="button">Click me</button>

JavaScript

function simulateClick() {
  var evt = new MouseEvent("click", {
    bubbles: true,
    cancelable: true,
    view: window
  });
  var cb = document.getElementById("checkbox"); //element to click on
  var canceled = !cb.dispatchEvent(evt);
  if(canceled) {
    // A handler called preventDefault
    alert("canceled");
  } else {
    // None of the handlers called preventDefault
    alert("not canceled");
  }
}
document.getElementById("button").addEventListener('click', simulateClick);

Result

{{EmbedLiveSample('Example')}}

Specifications

Specification Status Comment
{{SpecName('CSSOM View','#extensions-to-the-mouseevent-interface', 'MouseEvent')}} {{Spec2('CSSOM View')}} Redefines MouseEvent from long to double. This means that a PointerEvent whose pointerType is mouse will be a double.
{{SpecName('Pointer Lock','#extensions-to-the-mouseevent-interface','MouseEvent')}} {{Spec2('Pointer Lock')}} From {{SpecName('DOM3 Events')}}, added movementX and movementY properties.
{{SpecName('CSSOM View', '#extensions-to-the-mouseevent-interface', 'MouseEvent')}} {{Spec2('CSSOM View')}} From {{SpecName('DOM3 Events')}}, added offsetX and offsetY, pageX and pageY, x, and y properties. Redefined screen, page, client, and coordinate (x and y) properties as double from long.
{{SpecName('UI Events', '#interface-mouseevent', 'MouseEvent')}} {{Spec2('UI Events')}}
{{SpecName('DOM3 Events','#events-mouseevents','MouseEvent')}} {{Spec2('DOM3 Events')}} From {{SpecName('DOM2 Events')}}, added the MouseEvent() constructor, the getModifierState() method and the buttons property.
{{SpecName('DOM2 Events','#Events-MouseEvent','MouseEvent')}} {{Spec2('DOM2 Events')}} Initial definition.

Browser compatibility

{{Compat("api.MouseEvent")}}

See also