提交 bb2fa975 编写于 作者: B bixuefeng

Bugfix: sendTouchEvent/sendMouseEvent add windowX/windowY/displayX/displayY

Signed-off-by: Nbixuefeng <bixuefeng@huawei.com>
Change-Id: I8c8ce79d098ec1d97c41d830d11f6227d557f6e1
上级 394aff5f
...@@ -137,6 +137,8 @@ sendMouseEvent(event: MouseEvent): boolean ...@@ -137,6 +137,8 @@ sendMouseEvent(event: MouseEvent): boolean
```ts ```ts
// xxx.ets // xxx.ets
import { IntentionCode } from '@ohos.multimodalInput.intentionCode'
class Utils { class Utils {
static rect_left static rect_left
static rect_top static rect_top
...@@ -199,11 +201,15 @@ struct IdExample { ...@@ -199,11 +201,15 @@ struct IdExample {
let rect = Utils.getComponentRect('onTouch') // 获取id为"onTouch"组件的矩形区域坐标 let rect = Utils.getComponentRect('onTouch') // 获取id为"onTouch"组件的矩形区域坐标
let touchPoint: TouchObject = { let touchPoint: TouchObject = {
id: 1, id: 1,
x: rect.left + (rect.right - rect.left) / 2, // 组件中心点x坐标
y: rect.top + (rect.bottom - rect.top) / 2, // 组件中心点y坐标
type: TouchType.Down, type: TouchType.Down,
screenX: rect.left + (rect.right - rect.left) / 2, // 组件中心点x坐标 x: rect.left + (rect.right - rect.left) / 2, // 相对于组件左上角的水平方向坐标
screenY: rect.left + (rect.right - rect.left) / 2, // 组件中心点y坐标 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) // 发送触摸事件 sendTouchEvent(touchPoint) // 发送触摸事件
touchPoint.type = TouchType.Up touchPoint.type = TouchType.Up
...@@ -222,10 +228,14 @@ struct IdExample { ...@@ -222,10 +228,14 @@ struct IdExample {
let mouseEvent: MouseEvent = { let mouseEvent: MouseEvent = {
button: MouseButton.Left, button: MouseButton.Left,
action: MouseAction.Press, action: MouseAction.Press,
x: rect.left + (rect.right - rect.left) / 2, // 组件中心点x坐标 x: rect.left + (rect.right - rect.left) / 2, // 相对于组件左上角的水平方向坐标
y: rect.top + (rect.bottom - rect.top) / 2, // 组件中心点y坐标 y: rect.top + (rect.bottom - rect.top) / 2, // 相对于组件左上角的垂直方向坐标
screenX: rect.left + (rect.right - rect.left) / 2, // 组件中心点x坐标 screenX: rect.left + (rect.right - rect.left) / 2, // 相对于应用窗口左上角的水平方向坐标,API10已废弃,采用windowX替代
screenY: rect.top + (rect.bottom - rect.top) / 2, // 组件中心点y坐标 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, timestamp: 1,
target: { target: {
area: { area: {
...@@ -265,7 +275,8 @@ struct IdExample { ...@@ -265,7 +275,8 @@ struct IdExample {
keySource: 4, keySource: 4,
deviceId: 0, deviceId: 0,
metaKey: 0, metaKey: 0,
timestamp: 0 timestamp: 0,
intentionCode: IntentionCode.INTENTION_DOWN
} }
sendKeyEvent(keyEvent) // 发送按键事件 sendKeyEvent(keyEvent) // 发送按键事件
}, 2000) }, 2000)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册