event module¶
-
class
event
()¶ Provides functionality for creating and sending DOM events.
-
event.
isKeypressFiredKey
(key)¶ 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.
sendChar
(char, window)¶ Send character to the currently focused element.
This function handles casing of characters (sends the right charcode, and sends a shift key for uppercase chars). No other modifiers are handled at this point.
For now this method only works for English letters (lower and upper case) and the digits 0-9.
-
event.
sendKey
(key, window)¶ Send the non-character key to the focused element.
The name of the key should be the part that comes after “DOM_VK_” in the KeyboardEvent constant name for this key. No modifiers are handled at this point.
-
event.
sendKeysToElement
(keyString, el, window)¶ Arguments: - keyString (string) –
- element (Element) –
- window (Window) –
-
event.
sendMouseEvent
(mouseEvent, target, window)¶ Sends a mouse event to given target.
Arguments: - mouseEvent (nsIDOMMouseEvent) – Event to send.
- target (DOMElement|string) – Target of event. Can either be an element or the ID of an element.
- window (Window) – Window object. Defaults to the current window.
Throws: TypeError – If the event is unsupported.
-
event.
sendSingleKey
(keyToSend, modifiers, window)¶ 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.
- window (Window) – Window object. If |window| is undefined, the event is synthesized in current window.
-
event.
sendString
(string, window)¶ Send string to the focused element.
For now this method only works for English letters (lower and upper case) and the digits 0-9.
-
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.
- window (Window) – Window object. Defaults to the current window.
Throws: TypeError – If unknown key.
-
event.
synthesizeKeyExpectEvent
(key, ev, expectedTarget, expectedEvent, testName, window)¶ Similar to synthesizeKey except that a test is performed to see if an event is fired at the right target as a result.
Arguments: - key (string) – Key to synthesise.
- ?> 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
- window (Window) – Window object. Defaults to the current window. To test that an event is not fired, use an expected type preceded by an exclamation mark, such as “!select”. aWindow is optional, and defaults to the current window object.
-
event.
synthesizeMouse
(element, offsetX, offsetY, opts, window)¶ 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”.
- window (Window) – Window object. Defaults to the current window.
-
event.
synthesizeMouseAtCenter
(element, event, window)¶ Call event.synthesizeMouse with coordinates at the centre of the target.
-
event.
synthesizeMouseExpectEvent
(target, offsetX, offsetY, ev, expectedTarget, expectedEvent, testName, window)¶ 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.
- window (Window) – Window object. Defaults to the current window.
-
event.
synthesizeQuerySelectedText
(window)¶ Synthesize a query selected text event.
Arguments: - Window (Window) – object. Defaults to the current window.
Returns: nsIQueryContentEventResult|null – Event’s result, or null if it failed.
-
event.
synthesizeSelectionSet
(offset, length, reverse, window)¶ Synthesize a selection set event.
Arguments: - offset (number) – Character offset. 0 means the first character in the selection root.
- length (number) – Length of the text. If the length is too long, the extra length is ignored.
- reverse (boolean) – If true, the selection is from |aOffset + aLength| to |aOffset|. Otherwise, from |aOffset| to |aOffset + aLength|.
- window (Window) – Window object. Defaults to the current window.
Returns: True, if succeeded. Otherwise false.
-