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

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 16 17

> **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

**System capability**: SystemCapability.MultimodalInput.Input.Core

18 19 20 21 22 23
| 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 已提交
24 25 26 27 28

## ToolType

**System capability**: SystemCapability.MultimodalInput.Input.Core

29 30 31 32 33 34 35 36 37 38
| 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 已提交
39 40 41 42 43

## SourceType 

**System capability**: SystemCapability.MultimodalInput.Input.Core

44 45 46 47 48
| Name | Value | Description |
| ---- | ----- | ----------- |
| TOUCH_SCREEN | 0 | Touchscreen|
| PEN          | 1 | Stylus     |
| TOUCH_PAD    | 2 | Touchpad   |
S
shawn_he 已提交
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72

## Touch

**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.|
73
| toolType | ToolType | Yes| No| Tool type.|
S
shawn_he 已提交
74 75 76 77 78 79 80 81 82 83 84

## TouchEvent

**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.|