event module

class event()

Provides functionality for creating and sending DOM events.

event.isKeypressFiredKey(key, win)

Returns true if the given key should cause keypress event when widget handles the native key event. Otherwise, false.

The key code should be one of consts of KeyboardEvent.DOM_VK_*, or a key name begins with “VK_”, or a character.

event.sendKeysToElement(keyString, element, win)
Arguments
  • keyString (string) –

  • element (Element) –

  • win (Window) –

event.sendSingleKey(keyToSend, modifiers, win)

Synthesize a key event for a single key.

Arguments
  • keyToSend (string) – Code point or normalized key value

  • boolean> modifiers (Object.<string,) – Object with properties used in KeyboardEvent (shiftkey, repeat, …) as well as, the event |type| such as keydown. All properties are optional.

  • win (Window) – Window object.

event.synthesizeKey(key, event, win)

Synthesise a key event.

It is targeted at whatever would be targeted by an actual keypress by the user, typically the focused element.

Arguments
  • key (string) – Key to synthesise. Should either be a character or a key code starting with “VK_” such as VK_RETURN, or a normalized key value.

  • ?> event (Object.<string,) – Object which may contain the properties shiftKey, ctrlKey, altKey, metaKey, accessKey, type. If the type is specified (keydown or keyup), a key event of that type is fired. Otherwise, a keydown, a keypress, and then a keyup event are fired in sequence.

  • win (Window) – Window object.

Throws

TypeError – If unknown key.

event.synthesizeMouse(element, offsetX, offsetY, opts, win)

Synthesise a mouse event on a target.

The actual client point is determined by taking the aTarget’s client box and offseting it by offsetX and offsetY. This allows mouse clicks to be simulated by calling this method.

If the type is specified, an mouse event of that type is fired. Otherwise, a mousedown followed by a mouse up is performed.

Arguments
  • element (Element) – Element to click.

  • offsetX (number) – Horizontal offset to click from the target’s bounding box.

  • offsetY (number) – Vertical offset to click from the target’s bounding box.

  • ?> opts (Object.<string,) – Object which may contain the properties “shiftKey”, “ctrlKey”, “altKey”, “metaKey”, “accessKey”, “clickCount”, “button”, and “type”.

  • win (Window) – Window object.

event.synthesizeMouseExpectEvent(target, offsetX, offsetY, ev, expectedTarget, expectedEvent, testName, win)

Similar to event.synthesizeMouse except that a test is performed to see if an event is fired at the right target as a result.

To test that an event is not fired, use an expected type preceded by an exclamation mark, such as “!select”. This might be used to test that a click on a disabled element doesn’t fire certain events for instance.

Arguments
  • target (Element) – Synthesise the mouse event on this target.

  • offsetX (number) – Horizontal offset from the target’s bounding box.

  • offsetY (number) – Vertical offset from the target’s bounding box.

  • ?> ev (Object.<string,) – Object which may contain the properties shiftKey, ctrlKey, altKey, metaKey, accessKey, type.

  • expectedTarget (Element) – Expected originalTarget of the event.

  • expectedEvent (DOMEvent) – Expected type of the event, such as “select”.

  • testName (string) – Test name when outputing results.

  • win (Window) – Window object.