js-apis-touchevent.md 4.2 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 (touchscreen) events reported by an input device.
S
shawn_he 已提交
4

S
shawn_he 已提交
5 6
>  **NOTE**
>
S
shawn_he 已提交
7 8 9 10 11 12 13 14 15 16
> 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 已提交
17
Enumerates touch 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
| Name    | Value  | Description  |
| ------ | ------ | ---- |
| CANCEL | 0 | Cancellation of touch.|
| DOWN   | 1 | Pressing of touch.|
| MOVE   | 2 | Moving of touch.|
| UP     | 3 | Lifting of touch.|
S
shawn_he 已提交
27 28 29

## ToolType

S
shawn_he 已提交
30
Enumerates touch tool types.
S
shawn_he 已提交
31

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

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

## SourceType 

S
shawn_he 已提交
47
Enumerates touch source types.
S
shawn_he 已提交
48

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

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

## Touch

S
shawn_he 已提交
59
Defines the touch point information.
S
shawn_he 已提交
60

S
shawn_he 已提交
61 62
**System capability**: SystemCapability.MultimodalInput.Input.Core

S
shawn_he 已提交
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| Name         | Type  | Readable  | Writable  | Description                                 |
| ----------- | ------ | ---- | ---- | ----------------------------------- |
| id          | number | Yes   | No   | Touch event ID.                               |
| pressedTime | number | Yes   | No   | Press timestamp, in μs.                            |
| 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 touch area.                          |
| height      | number | Yes   | No   | Height of the touch area.                          |
| 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   | X coordinate of the center point of the tool area.                          |
| toolY       | number | Yes   | No   | Y coordinate of the center point 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.                          |
| toolType    | [ToolType](#tooltype) | Yes   | No   | Tool type.                               |
S
shawn_he 已提交
83 84 85

## TouchEvent

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

S
shawn_he 已提交
88 89
**System capability**: SystemCapability.MultimodalInput.Input.Core

S
shawn_he 已提交
90 91 92 93 94 95
| Name        | Type      | Readable  | Writable  | Description       |
| ---------- | ---------- | ---- | ---- | --------- |
| action     | [Action](#action)     | Yes   | No   | Touch event type.    |
| touch      | [Touch](#touch)      | Yes   | No   | Current touch point.  |
| touches    | Touch[]    | Yes   | No   | All touch points.    |
| sourceType | [SourceType](#sourcetype) | Yes   | No   | Touch source type.|