提交 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
```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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册