js-apis-mouseevent.md 4.9 KB
Newer Older
S
shawn_he 已提交
1
# @ohos.multimodalInput.mouseEvent (Mouse Event)
S
shawn_he 已提交
2

S
shawn_he 已提交
3
The **mouseEvent** module provides mouse events reported by an input device.
S
shawn_he 已提交
4

S
shawn_he 已提交
5 6
>  **NOTE**
>
S
shawn_he 已提交
7 8 9 10 11
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.

## Modules to Import

```js
S
shawn_he 已提交
12
import { Action, Button, Axis, AxisValue, MouseEvent } from '@ohos.multimodalInput.mouseEvent';
S
shawn_he 已提交
13 14 15 16
```

## Action

S
shawn_he 已提交
17
Enumerates mouse event types.
S
shawn_he 已提交
18

S
shawn_he 已提交
19 20
**System capability**: SystemCapability.MultimodalInput.Input.Core

S
shawn_he 已提交
21 22 23 24 25 26 27 28 29
| Name       | Value| Description                |
| ----------- | -------- | -------------------- |
| CANCEL      | 0   | Cancellation of a mouse action.            |
| MOVE        | 1   | Moving of the mouse pointer.            |
| BUTTON_DOWN | 2   | Pressing of a mouse button.        |
| BUTTON_UP   | 3   | Release of a mouse button.        |
| AXIS_BEGIN  | 4   | Beginning of the axis event associated with the mouse.|
| AXIS_UPDATE | 5   | Updating of the axis event associated with the mouse.|
| AXIS_END    | 6   | Ending of the axis event associated with the mouse.|
S
shawn_he 已提交
30 31 32

## Button

S
shawn_he 已提交
33
Enumerates mouse buttons.
S
shawn_he 已提交
34

S
shawn_he 已提交
35 36
**System capability**: SystemCapability.MultimodalInput.Input.Core

S
shawn_he 已提交
37 38 39 40 41 42 43 44 45 46
| Name     | Value | Description   |
| ------- | ------| ----- |
| LEFT    | 0 | Left button on the mouse. |
| MIDDLE  | 1 | Middle button on the mouse. |
| RIGHT   | 2 | Right button on the mouse. |
| SIDE    | 3 | Side button on the mouse.|
| EXTRA   | 4 | Extended button on the mouse.|
| FORWARD | 5 | Forward button on the mouse.|
| BACK    | 6 | Back button on the mouse.|
| TASK    | 7 | Task button on the mouse.|
S
shawn_he 已提交
47 48 49

## Axis

S
shawn_he 已提交
50 51
Enumerates mouse axis types.

S
shawn_he 已提交
52 53
**System capability**: SystemCapability.MultimodalInput.Input.Core

S
shawn_he 已提交
54 55 56 57 58
| Name               | Value    | Description   |
| ----------------- | ------- | ----- |
| SCROLL_VERTICAL   | 0 | Vertical scroll axis.|
| SCROLL_HORIZONTAL | 1 | Horizontal scroll axis.|
| PINCH             | 2 | Pinch axis.  |
S
shawn_he 已提交
59 60 61 62


## AxisValue

S
shawn_he 已提交
63
Defines the mouse axis type and axis value.
S
shawn_he 已提交
64

S
shawn_he 已提交
65 66
**System capability**: SystemCapability.MultimodalInput.Input.Core

S
shawn_he 已提交
67 68 69 70
| Name   | Type  | Readable  | Writable  | Description  |
| ----- | ------ | ---- | ---- | ---- |
| axis  | Axis   | Yes   | No   | Axis type. |
| value | number | Yes   | No   | Axis value. |
S
shawn_he 已提交
71 72 73 74


## MouseEvent

S
shawn_he 已提交
75
Defines the mouse event.
S
shawn_he 已提交
76

S
shawn_he 已提交
77 78
**System capability**: SystemCapability.MultimodalInput.Input.Core

S
shawn_he 已提交
79 80
| Name            | Type       | Readable  | Writable  | Description                                      |
| -------------- | ----------- | ---- | ---- | ---------------------------------------- |
S
shawn_he 已提交
81
| action         | [Action](#action)      | Yes   | No   | Mouse event action.                                  |
S
shawn_he 已提交
82 83 84 85 86 87
| screenX        | number      | Yes   | No   | Horizontal coordinate of the mouse pointer on the screen.                            |
| screenY        | number      | Yes   | No   | Vertical coordinate of the mouse pointer on the screen.                            |
| windowX        | number      | Yes   | No   | Horizontal coordinate of the mouse pointer in the window.                              |
| windowY        | number      | Yes   | No   | Vertical coordinate of the mouse pointer in the window.                              |
| rawDeltaX      | number      | Yes   | No   | Horizontal coordinate offset relative to the previous reported mouse pointer position.|
| rawDeltaY      | number      | Yes   | No   | Vertical coordinate offset relative to the previous reported mouse pointer position.                         |
S
shawn_he 已提交
88
| button         | [Button](#button)      | Yes   | No   | Mouse button                              
S
shawn_he 已提交
89 90 91
| pressedButtons | Button[]    | Yes   | No   | Button being pressed.                             |
| axes           | AxisValue[] | Yes   | No   | All axis data contained in the event.                              |
| pressedKeys    | KeyCode[]   | Yes   | No   | List of pressed keys.                           |
S
shawn_he 已提交
92
| ctrlKey        | boolean     | Yes   | No   | Whether ctrlKey is being pressed.<br>The value **true** indicates that the key is pressed, and the value **false** indicates the opposite.   |
S
shawn_he 已提交
93 94 95 96
| altKey         | boolean     | Yes   | No   | Whether altKey is being pressed.                        |
| shiftKey       | boolean     | Yes   | No   | Whether shiftKey is being pressed.                      |
| logoKey        | boolean     | Yes   | No   | Whether logoKey is being pressed.                       |
| fnKey          | boolean     | Yes   | No   | Whether fnKey is being pressed.                         |
S
shawn_he 已提交
97
| capsLock       | boolean     | Yes   | No   | Whether capsLock is active.<br>The value **true** indicates that capsLock is active, and the value **false** indicates the opposite. |
S
shawn_he 已提交
98 99
| numLock        | boolean     | Yes   | No   | Whether numLock is active.                       |
| scrollLock     | boolean     | Yes   | No   | Whether scrollLock is active.                    |