diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-component-id.md b/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-component-id.md index d4161f28b1303642db2c77ce388c230154a8acd6..aed9b7dc9cd9e055c420bc6534b45acbd94369e0 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-component-id.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-component-id.md @@ -137,6 +137,8 @@ sendMouseEvent(event: MouseEvent): boolean ```ts // xxx.ets +import { IntentionCode } from '@ohos.multimodalInput.intentionCode' + class Utils { static rect_left static rect_top @@ -199,11 +201,15 @@ struct IdExample { let rect = Utils.getComponentRect('onTouch') // 获取id为"onTouch"组件的矩形区域坐标 let touchPoint: TouchObject = { id: 1, - x: rect.left + (rect.right - rect.left) / 2, // 组件中心点x坐标 - y: rect.top + (rect.bottom - rect.top) / 2, // 组件中心点y坐标 type: TouchType.Down, - screenX: rect.left + (rect.right - rect.left) / 2, // 组件中心点x坐标 - screenY: rect.left + (rect.right - rect.left) / 2, // 组件中心点y坐标 + x: rect.left + (rect.right - rect.left) / 2, // 相对于组件左上角的水平方向坐标 + y: rect.top + (rect.bottom - rect.top) / 2, // 相对于组件左上角的垂直方向坐标 + screenX: rect.left + (rect.right - rect.left) / 2, // 相对于应用窗口左上角的水平方向坐标,API10已废弃,采用windowX替代 + screenY: rect.left + (rect.right - rect.left) / 2, // 相对于应用窗口左上角的垂直方向坐标,API10已废弃,采用windowY替代 + windowX: rect.left + (rect.right - rect.left) / 2, // 相对于应用窗口左上角的水平方向坐标 + windowY: rect.left + (rect.right - rect.left) / 2, // 相对于应用窗口左上角的垂直方向坐标 + displayX: rect.left + (rect.right - rect.left) / 2, // 相对于设备屏幕左上角的水平方向坐标 + displayY: rect.left + (rect.right - rect.left) / 2, // 相对于设备屏幕左上角的垂直方向坐标 } sendTouchEvent(touchPoint) // 发送触摸事件 touchPoint.type = TouchType.Up @@ -222,10 +228,14 @@ struct IdExample { let mouseEvent: MouseEvent = { button: MouseButton.Left, action: MouseAction.Press, - x: rect.left + (rect.right - rect.left) / 2, // 组件中心点x坐标 - y: rect.top + (rect.bottom - rect.top) / 2, // 组件中心点y坐标 - screenX: rect.left + (rect.right - rect.left) / 2, // 组件中心点x坐标 - screenY: rect.top + (rect.bottom - rect.top) / 2, // 组件中心点y坐标 + x: rect.left + (rect.right - rect.left) / 2, // 相对于组件左上角的水平方向坐标 + y: rect.top + (rect.bottom - rect.top) / 2, // 相对于组件左上角的垂直方向坐标 + screenX: rect.left + (rect.right - rect.left) / 2, // 相对于应用窗口左上角的水平方向坐标,API10已废弃,采用windowX替代 + screenY: rect.left + (rect.right - rect.left) / 2, // 相对于应用窗口左上角的垂直方向坐标,API10已废弃,采用windowY替代 + windowX: rect.left + (rect.right - rect.left) / 2, // 相对于应用窗口左上角的水平方向坐标 + windowY: rect.left + (rect.right - rect.left) / 2, // 相对于应用窗口左上角的垂直方向坐标 + displayX: rect.left + (rect.right - rect.left) / 2, // 相对于设备屏幕左上角的水平方向坐标 + displayY: rect.left + (rect.right - rect.left) / 2, // 相对于设备屏幕左上角的垂直方向坐标 timestamp: 1, target: { area: { @@ -265,7 +275,8 @@ struct IdExample { keySource: 4, deviceId: 0, metaKey: 0, - timestamp: 0 + timestamp: 0, + intentionCode: IntentionCode.INTENTION_DOWN } sendKeyEvent(keyEvent) // 发送按键事件 }, 2000)