Skip to content

event-handling

Several helper classes provide low-level event-handling capabilities.

Event objects are normally created by ScriptUI and passed to your event handler. However, you can simulate a user action by constructing an event object using ScriptUI.events.createEvent(), and sending it to a target object’s controlobj-dispatchEvent function.

A helper object, Keyboard state object, provides global access to the keyboard state during function execution, outside the event-handling framework.


Encapsulates input event information for an event that propagates through a container and control hierarchy. This is a base class for the more specialized KeyboardEvent object and MouseEvent object.


Both keyboard and mouse events have these properties.

eventObj.bubbles

When true, the event supports the bubbling phase.

Boolean


eventObj.cancelable

When true, the handler can call this object’s preventDefault() method to cancel the default action of the event.

Boolean


eventObj.currentTarget

The element object where the currently executing handler was registered.

This could be an ancestor of the target object, if the handler is invoked during the capture or bubbling phase.

Object


eventObj.eventPhase

Current event propagation phase. One of these constants:

  • Event.NOT_DISPATCHING
  • Event.CAPTURING_PHASE
  • Event.AT_TARGET
  • Event.BUBBLING_PHASE

Number


eventObj.target

The element object where the event occurred.

Object


eventObj.timeStamp

Time the event was initiated. A JavaScript Date object.

Object


eventObj.type

The name of the event that occurred. Predefined events types are:

  • "blur"
  • "change"
  • "changing"
  • "enterKey"
  • "focus"
  • "move"
  • "moving"
  • "resize"
  • "resizing"
  • "show"

Additional type names apply specifically to keyboard and mouse events.

String


eventObj.view

The container or control object that dispatched the event.

Container or Control object


eventObj.initUIEvent(eventName, bubble, isCancelable, view, detail)

Modifies an event before it is dispatched to its targets. Takes effect only if UIEvent.eventPhase is Event.NOT_DISPATCHING.

Ignored at all other phases.

ParameterTypeDescription
eventNameStringThe event name string.
bubbleBooleanWhen true, the event should be triggered in ancestors of the target object during the bubbling phase.
isCancelableBooleanWhen true, the event can be cancelled.
viewContainer or Control objectThe container or control object that dispatched the event.
detailAnyDetails of the event, which vary according to the event type. The value is 1 or 2 for the click event, indicating a single or double click.

Nothing


eventObj.preventDefault()

Cancels the default action of this event, if this event is cancelable (that is, cancelable is true).

For example, the default click action of an OK button is to close the containing dialog; this call prevents that behavior.

Nothing


eventObj.stopPropagation()

Stops event propagation (bubbling and capturing) after executing the handler or handlers at the current target.

Nothing


This type of object is passed to your registered event handler when a keyboard-input event occurs. The properties reflect the keypress and key modifier state at the time the keyboard event was generated.

All properties are read only.

In addition to the properties defined for UIEvent base class, a keyboard event has these properties.

eventObj.altKey

When true, the ALT key was active.

Value is undefined if the keyIdentifier is for a modifier key.

Boolean


eventObj.ctrlKey

When true, the CTRL key was active.

Value is undefined if the keyIdentifier is for a modifier key.

Boolean


eventObj.metaKey

When true, the META or COMMAND key was active.

Value is undefined if the keyIdentifier is for a modifier key.

Boolean


eventObj.shiftKey

When true, the SHIFT key was active.

Value is undefined if the keyIdentifier is for a modifier key.

Boolean


eventObj.keyIdentifier

The key whose keypress generated the event, as a W3C identifier contained in a string; for example, "U+0044". See W3 Keyset Article.

String


eventObj.keyLocation

A constant that identifies where on the keyboard the keypress occurred.

One of:

  • DOM_KEY_LOCATION_STANDARD
  • DOM_KEY_LOCATION_LEFT
  • DOM_KEY_LOCATION_RIGHT
  • DOM_KEY_LOCATION_NUMPAD

Number


eventObj.keyName

The key whose keypress generated the event, as a simple key name; for example "A".

String


eventObj.type

The name of the event that occurred. Key events types are:

  • keyup
  • keydown

String


In addition to the functions defined for UIEvent base class, a keyboard event has these functions.

eventObj.getModifierState(keyIdentifier)

Get the current modifier keys being used in this event.

ParameterTypeDescription
keyIdentifierStringA string containing a modifier key identifier, one of:
- Alt
- CapsLock
- Control
- Meta
- NumLock
- Scroll
- Shift

Boolean. true if the given modifier was active when the event occurred, false otherwise.


eventObj.initKeyboardEvent(eventName, bubble, isCancelable, view, keyID, keyLocation, modifiersList)

Reinitializes the object, allowing you to change the event properties after construction. Arguments set the corresponding properties.

ParameterTypeDescription
eventNameStringThe event name string.
bubbleBooleanWhen true, the event should be triggered in ancestors of the target object during the bubbling phase.
isCancelableBooleanWhen true, the event can be cancelled.
viewContainer or Control objectThe container or control object that dispatched the event.
keyIDStringSets the keyIdentifier value.
keyLocationStringSets the keyLocation. value.
modifiersListStringA whitespace-separated string of modifier key names, such as “Control Alt”.

Nothing


This type of object is passed to your registered event handler when a mouse-input event occurs. The properties reflect the button and modifier-key state and pointer position at the time the event was generated.

In the case of nested elements, mouse event types are always targeted at the most deeply nested element. Ancestors of the targeted element can use bubbling to obtain notification of mouse events which occur within its descendent elements.

In addition to the properties defined for UIEvent base class, a mouse event has these properties.

All properties are read only.


eventObj.altKey

When true, the ALT key was active.

Value is undefined if the keyIdentifier is for a modifier key.

Boolean


eventObj.button

Which mouse button changed state.

One of:

  • 0: The left button of a two- or three-button mouse or the one button on a one-button mouse, used to activate a UI button or select text.
  • 1: The middle button of a three-button mouse, or the mouse wheel.
  • 2: The right button, used to display a context menu, if present.

Some mice may provide or simulate more buttons, and values higher than 2 represent such buttons.

Number


eventObj.clientX

eventObj.clientY

The horizontal and vertical coordinates at which the event occurred relative to the target object. The origin is the top left of the control or window, inside any border decorations.

Number


eventObj.ctrlKey

When true, the CTRL key was active.

Value is undefined if the keyIdentifier is for a modifier key.

Boolean


eventObj.detail

Details of the event, which vary according to the event type.

For the click, mousedown, and mouseup events, the value is 1 for a single click, or 2 for a double click.

Number


eventObj.metaKey

When true, the META or COMMAND key was active.

Value is undefined if the keyIdentifier is for a modifier key.

Boolean


eventObj.relatedTarget

  • For a mouseover event, the UI element the pointer is leaving, if any.
  • For a mouseout event, the UI element the pointer is entering, if any.

Otherwise undefined.

Object


eventObj.screenX

eventObj.screenY

The horizontal and vertical coordinates at which the event occurred relative to the screen.

Number


eventObj.shiftKey

When true, the SHIFT key was active.

Value is undefined if the keyIdentifier is for a modifier key.

Boolean


eventObj.type

The name of the event that occurred. Mouse events types are:

  • "mousedown"
  • "mouseup"
  • "mousemove"
  • "mouseover"
  • "mouseout"
  • "click" (detail = 1 for single, 2 for double)

The sequence of click events is: mousedown, mouseup, click.

String


In addition to the functions defined for UIEvent base class, a mouse event has these functions.


eventObj.getModifierState(keyIdentifier)

Get the current modifier keys being used in this event.

ParameterTypeDescription
keyIdentifierStringA string containing a modifier key identifier, one of:
- "Alt"
- "CapsLock"
- "Control"
- "Meta"
- "NumLock"
- "Scroll"
- "Shift"

Boolean. true if the given modifier was active when the event occurred, false otherwise.


eventObj.initMouseEvent(
eventName,
bubble,
isCancelable,
view,
detail,
screenX,
screenY,
clientX,
clientY,
ctrlKey,
altKey,
shiftKey,
metaKey,
button,
relatedTarge
)

Reinitializes the object, allowing you to change the event properties after construction. Arguments set the corresponding properties.

ParameterTypeDescription
eventNameStringThe event name string.
bubbleBooleanWhen true, the event should be triggered in ancestors of the target object during the bubbling phase.
isCancelableBooleanWhen true, the event can be cancelled.
viewContainer or Control objectThe container or control object that dispatched the event.
detailNumberSets the single-double click value for the click event.
screenX, screenYNumberSets the event coordinates relative to the screen.
clientX, clientYNumberSets the event coordinates relative to the target object. The origin is the top left of the control or window, inside any border decorations.
ctrlKey, altKey, metaKeyBooleanSets the modifier key states.
buttonNumberSets the mouse button.
relatedTargetObjectOptional. Sets the related target, if any, for a mouseover or mouseout event.

Nothing