js-apis-pointer.md 3.3 KB
Newer Older
L
liuwei 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# 鼠标指针

鼠标指针管理模块,用于提供鼠标指针相关属性接口。

> **说明**:
>
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

## 导入模块

```js
import pointer from '@ohos.multimodalInput.pointer';
```

L
liuwei 已提交
15
## pointer.setPointerVisibele
L
liuwei 已提交
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41

setPointerVisible(visible: boolean, callback: AsyncCallback<void>):  void;

设置鼠标指针显示或者隐藏,使用callback方式作为异步方法。

**系统能力**:SystemCapability.MultimodalInput.Input.Pointer

**参数**

| 参数     | 类型                      | 必填 | 说明                                      |
| -------- | ------------------------- | ---- | ----------------------------------------- |
| visible  | boolean                   | 是   | true: 鼠标指针显示; false: 鼠标指针隐藏。 |
| callback | AysncCallback<void> | 是   | 回调函数,异步返回查询结果。              |

**示例**

```js
pointer.setPointerVisible(true, (err, data) => {
    if (err) {
        console.log(`set pointer visible failed. err=${JSON.stringify(err)}`);
        return;
    }
    console.log(`set pointer visible success.`);
);
```

L
liuwei 已提交
42
## pointer.setPointerVisible
L
liuwei 已提交
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114

setPointerVisible(visible: boolean) : Promise<void>;

设置鼠标指针显示或者隐藏,使用Promise方式作为异步方法。

**系统能力**:SystemCapability.MultimodalInput.Input.Pointer

**参数**

| 参数    | 类型    | 必填 | 说明                                      |
| ------- | ------- | ---- | ----------------------------------------- |
| visible | boolean | 是   | true: 鼠标指针显示; false: 鼠标指针隐藏。 |

**返回值**

| 参数                | 说明                            |
| ------------------- | ------------------------------- |
| Promise<void> | Promise实例,用于异步获取结果。 |

**示例**

```js
pointer.setPointerVisible(false).then( data => {
        console.log(`set mouse pointer visible success`);
    }, data => {
    console.log(`set mouse pointer visible failed err=${JSON.stringify(data)}`);
});
```

## pointer.isPointerVisible

isPointerVisible(callback: AsyncCallback<boolean>) : void;

获取鼠标指针是否显示,使用callback方式作为异步方法。

**系统能力**:SystemCapability.MultimodalInput.Input.Pointer

**参数**

| 参数     | 类型                         | 必填 | 说明                         |
| -------- | ---------------------------- | ---- | ---------------------------- |
| callback | AsyncCallback<boolean> | 是   | 回调函数,异步返回查询结果。 |

**示例**

```js
pointer.isPointerVisible((visible)=>{
    console.log("The mouse pointer visible attributes is " + visible);
});
```

## pointer.isPointerVisible

isPointerVisible(): Promise<boolean>

获取鼠标指针是否显示,使用Promise方式作为异步方法。

**系统能力**:SystemCapability.MultimodalInput.Input.Pointer

**返回值**

| 参数                   | 说明                            |
| ---------------------- | ------------------------------- |
| Promise<boolean> | Promise实例,用于异步获取结果。 |

**示例**

```js
pointer.isPointerVisible().then( data => {
    console.log(`isPointerThen success data=${JSON.stringify(data)}`);
});
```