js-apis-touchevent.md 3.4 KB
Newer Older
S
shawn_he 已提交
1
# @ohos.multimodalInput.touchEvent (Touch Event)
S
shawn_he 已提交
2

S
shawn_he 已提交
3
The **touchEvent** module provides touch events reported by an input device.
S
shawn_he 已提交
4 5 6 7 8 9 10 11 12 13 14 15

> **NOTE**<br>
> 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
import {Action,ToolType,SourceType,Touch,TouchEvent} from '@ohos.multimodalInput.touchEvent';
```

## Action

S
shawn_he 已提交
16 17
Enumerates touch actions.

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

S
shawn_he 已提交
20 21 22 23 24 25
| Name   | Value | Description |
| ------ | ----- | ----------- |
| CANCEL | 0 | Cancellation of the touch action.|
| DOWN   | 1 | Pressing of touch.               |
| MOVE   | 2 | Moving of touch.                 |
| UP     | 3 | Lifting of touch.                |
S
shawn_he 已提交
26 27 28

## ToolType

S
shawn_he 已提交
29 30
Enumerates tool types.

S
shawn_he 已提交
31 32
**System capability**: SystemCapability.MultimodalInput.Input.Core

S
shawn_he 已提交
33 34 35 36 37 38 39 40 41 42
| Name | Value | Description |
| ---- | ----- | ----------- |
| FINGER | 0 | Finger|
| PEN | 1 | Pen|
| RUBBER | 2 | Eraser|
| BRUSH | 3 | Brush|
| PENCIL | 4 | Pencil|
| AIRBRUSH | 5 | Air brush|
| MOUSE | 6 | Mouse|
| LENS | 7 | Lens|
S
shawn_he 已提交
43 44 45

## SourceType 

S
shawn_he 已提交
46 47
Enumerates source types.

S
shawn_he 已提交
48 49
**System capability**: SystemCapability.MultimodalInput.Input.Core

S
shawn_he 已提交
50 51 52 53 54
| Name | Value | Description |
| ---- | ----- | ----------- |
| TOUCH_SCREEN | 0 | Touchscreen|
| PEN          | 1 | Stylus     |
| TOUCH_PAD    | 2 | Touchpad   |
S
shawn_he 已提交
55 56 57

## Touch

S
shawn_he 已提交
58 59
Defines a touch action.

S
shawn_he 已提交
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
**System capability**: SystemCapability.MultimodalInput.Input.Core

| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| id | number | Yes| No| Pointer ID.|
| pressedTime  | number | Yes| No| Time stamp when touch is pressed.|
| screenX | number | Yes| No| X coordinate of the touch position on the screen.|
| screenY | number | Yes| No| Y coordinate of the touch position on the screen.|
| windowX | number | Yes| No| X coordinate of the touch position in the window.|
| windowY | number | Yes| No| Y coordinate of the touch position in the window.|
| pressure | number | Yes| No| Pressure value. The value range is [0.0, 1.0]. The value 0.0 indicates that the pressure is not supported.|
| width | number | Yes| No| Width of the contact area where touch is pressed.|
| height | number | Yes| No| Height of the contact area where touch is pressed.|
| tiltX | number | Yes| No| Angle relative to the YZ plane. The value range is [-90, 90]. A positive value indicates a rightward tilt.|
| tiltY | number | Yes| No| Angle relative to the XZ plane. The value range is [-90, 90]. A positive value indicates a downward tilt.|
| toolX | number | Yes| No| Center point X of the tool area.|
| toolY | number | Yes| No| Center point Y of the tool area.|
| toolWidth | number | Yes| No| Width of the tool area.|
| toolHeight | number | Yes| No| Height of the tool area.|
| rawX | number | Yes| No| X coordinate of the input device.|
| rawY | number | Yes| No| Y coordinate of the input device.|
S
shawn_he 已提交
81
| toolType | ToolType | Yes| No| Tool type.|
S
shawn_he 已提交
82 83 84

## TouchEvent

S
shawn_he 已提交
85 86
Defines a touch event.

S
shawn_he 已提交
87 88 89 90 91 92 93 94
**System capability**: SystemCapability.MultimodalInput.Input.Core

| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| action | Action | Yes| No| Touch action.|
| touch | Touch | Yes| No| Current touch point.|
| touches | Touch[] | Yes| No| All touch points.|
| sourceType | SourceType | Yes| No| Device type of the touch source.|