### Hierarchy

- InputEvent

An InputEvent represents a mouse or keyboard or touch event. The principal properties hold information about a particular input event. These properties include the documentPoint at which a mouse event occurred in document coordinates, the corresponding point in view/element coordinates, viewPoint, the key for keyboard events, and the modifiers and button at the time. Additional descriptive properties include clickCount, delta, timestamp, and the source event event (if available).

Many of its properties are provided for convenient access to the state of the input event, such as asking whether the control key was held down at the time, or the targetObject (a GraphObject) that the mouse was over .

When real events fire on the Diagram, InputEvents are created automatically set update the value of Diagram.lastInput. These events set the value of event with the backing browser-defined Event, which may be a MouseEvent, KeyboardEvent, PointerEvent, and so on.

InputEvents backed by MouseEvents set both button, the button that caused the action, and buttons, the set of buttons currently pressed after the action has happened. By default a user-created InputEvent sets button and buttons as if the event was a left-click.

You can create InputEvents and set the value of Diagram.lastInput in order to simulate user actions in tools. This can be useful for testing. See the Robot extension sample for an example of creating InputEvents to simulate user input.

## Index

### Constructors

- constructor

### Properties

- alt
- bubbles
- button
- buttons
- clickCount
- control
- delta
- diagram
- documentPoint
- down
- event
- handled
- isMultiTouch
- isTouchEvent
- key
- left
- meta
- middle
- modifiers
- right
- shift
- targetDiagram
- targetObject
- timestamp
- up
- viewPoint

### Methods

- copy

## Constructors

### constructor

- new InputEvent(): InputEvent

- The InputEvent class constructor produces an empty InputEvent. You should never need to call this constructor. But if you do, you must first set diagram to the Diagram before any other use.

  #### Returns InputEvent

## Properties

### alt: boolean

- Gets or sets whether the alt key is being held down. This is true if the key was pressed at the time of the event.

  see

    modifiers, control, shift, meta

### bubbles: boolean

- Gets or sets whether the underlying event is prevented from bubbling up the hierarchy of HTML elements outside of the Diagram and whether any default action is canceled. Setting this is uncommon, but may be needed in some CommandHandler overrides in order to pass along events, such as keystrokes, to parent elements of the Diagram.

  Some event handlers may set this to true if the event should continue beyond the diagram's DIV and result in any default behaviors by the user-agent. The default value is false.

  since

    2.2

  see

    handled

### button: number

- Gets or sets the numerical value representing the mouse button that caused this event.

  Only one mouse button can cause an event at a time, but the set of all buttons currently pressed is kept in buttons.

  This property describes nothing during a `mousemove` event, since no button press causes the event. Instead, use the convenience properties left, middle, or right, or use the value of buttons to determine which mouse buttons are held during `mousemove` events.

  Common values for this property:

  - 0: left mouse button
  - 1: middle mouse button
  - 2: right mouse button

  Other values are possible if the mouse has additional buttons.

  If there is no associated event, setting this also sets the buttons flags to only this button.

  This property is valid if this is a mouse event.

  see

    buttons, left, middle, right

### buttons: number

- Gets or sets the set of buttons that are currently being held down. If this is a `mouseup` event, this set of buttons does not include the button that was just released, which will be the value of button.

  Common values for this property:

  - 0: not holding down any button
  - 1: left mouse button
  - 2: right mouse button
  - 3: both left and right mouse buttons
  - 4: middle mouse button
  - 5: middle and left mouse buttons
  - 6: middle and right mouse buttons
  - 7: all three common mouse buttons

  Other values are possible if the mouse has additional buttons.

  This property is valid if this is a mouse event.

  see

    button, left, middle, right

### clickCount: number

- Gets or sets whether this event represents a click or a double-click. It is zero if not a click; one if a single-click; two if a double-click. This property is valid if this is a mouse event.

### control: boolean

- Gets or sets whether the control key is being held down. This is true if the key was pressed at the time of the event.

  see

    modifiers, shift, alt, meta

### delta: number

- Gets or sets the amount of change associated with a mouse-wheel rotation. It is an abstract number, either positive or negative. This property is valid if this is a mouse-wheel event.

### diagram: Diagram

- Gets the source diagram associated with the event.

### documentPoint: Point

- Gets or sets the point at which this input event occurred, in document coordinates. The Point is in document coordinates, the same as the GraphObject.position for Parts in the diagram. This should be valid for mouse events. For keyboard events, this is the last available mouse point.

  see

    viewPoint, Diagram.transformViewToDoc, Diagram.transformDocToView

### down: boolean

- Gets or sets whether the InputEvent represents a mouse-down or a key-down event. The default value is false.

  since

    1.1

### event: Event

- Gets or sets the platform's user-agent-supplied event for this event. It may be null if no underlying event exists.

  see

    timestamp

### handled: boolean

- Gets or sets whether an InputEvent that applies to a GraphObject and bubbles up the chain of containing Panels is stopped from continuing up the chain.

  Some event handlers may set this to true to avoid getting any behavior from the containing Panels. The default value is false.

### isMultiTouch: boolean

- This property is true when the InputEvent is caused by a touch event that registered more than one touch.

  see

    isTouchEvent

  since

    1.5

### Read-only isTouchEvent: boolean

- This read-only property is true when the InputEvent is caused by a touch event.

  see

    isMultiTouch

  since

    1.5

### key: string

- Gets or sets the key pressed or released as this event. This property is valid if this is a keyboard event.

### left: boolean

- Gets or sets whether the logical left mouse button is being held down. This is true if the button was pressed at the time of the event.

  If this InputEvent has a event of type `MouseEvent` with `e.type` of "mouseup" or "mousedown", this property uses the value of button. Otherwise, it uses the value of buttons.

  When setting, this sets the value of buttons.

  see

    button, middle, right

### meta: boolean

- Gets or sets whether the meta key is being held down. This is true if the key was pressed at the time of the event.

  see

    modifiers, control, shift, alt

### middle: boolean

- Gets or sets whether the logical middle mouse button is being held down. This is true if the button was pressed at the time of the event.

  see

    button, left, right

### modifiers: number

- Gets or sets the modifier keys that were used with the mouse or keyboard event. The number will be a combination of flags representing Control, Shift, Alt or Meta.

  see

    control, shift, alt, meta

### right: boolean

- Gets or sets whether the logical right mouse button is being held down. This is true if the button was pressed at the time of the event.

  see

    button, left, middle

### shift: boolean

- Gets or sets whether the shift key is being held down. This is true if the key was pressed at the time of the event.

  see

    modifiers, control, alt, meta

### targetDiagram: Diagram

- Gets or sets the diagram associated with the canvas that the event is currently targeting.

### targetObject: GraphObject

- Gets or sets the GraphObject that is at the current mouse point, if any.

  For those events that are bubbled up the chain of parent Panels, this property provides access to the original GraphObject where the input event occurred.

  see

    handled

### timestamp: number

- Gets or sets the time at which the event occurred, in milliseconds.

### up: boolean

- Gets or sets whether the InputEvent represents a mouse-up or a key-up event. The default value is false.

  since

    1.1

### viewPoint: Point

- Gets or sets the point at which this input event occurred. The Point is in view coordinates within the viewport, not in document coordinates. This should be valid for mouse events. For keyboard events, this is the last available mouse point.

  see

    documentPoint, Diagram.transformViewToDoc, Diagram.transformDocToView

## Methods

### Virtual copy

- copy(): InputEvent

- Make a copy of this InputEvent.

  #### Returns InputEvent

Copyright © 1998-2022 by Northwoods Software Corporation.