# @ohos.multimodalInput.pointer (鼠标光标)

> phone 12+ | 2in1 13+ | tablet 12+ | tv 19+

鼠标光标管理模块，用于查询和设置鼠标光标相关属性。
> 说明
>
> * 本模块首批接口从API version 9开始支持。后续版本的新增接口，采用上角标单独标记接口的起始版本。

## 导入模块

```js
import { pointer } from '@kit.InputKit';
import { BusinessError } from '@kit.BasicServicesKit';
```

## pointer.setPointerVisible

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

设置光标显示/隐藏状态，此状态作用于当前进程的所有窗口。光标在屏幕上的实际显示/隐藏效果还受渲染服务进程影响。使用callback异步回调。

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

**参数**：

|参数名|类型|必填|说明|
|:-------|:------------------|:-|:----------------------------------------|
|visible|boolean|是|当前窗口鼠标光标是否显示。true表示显示，false表示不显示。|
|callback|AsyncCallback<void>|是|回调函数。当设置鼠标光标显示状态成功，err为undefined，否则为错误对象。|

**错误码**：

以下错误码的详细介绍请参见[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:----|:----------------------------------------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
|801|Capability not supported. 适用版本：18+|

**示例**：

```js
import { pointer } from '@kit.InputKit';
import { BusinessError } from '@kit.BasicServicesKit';

@Entry
@Component
struct Index {
  build() {
    RelativeContainer() {
      Text()
        .onClick(() => {
          try {
            // 设置鼠标指针可见性
            pointer.setPointerVisible(true, (error: BusinessError) => {
              if (error) {
                console.error(`Failed to set pointer cursor visible, Code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}.`);
                return;
              }
              console.info(`Succeeded in setting pointer cursor visible.`);
            });
          } catch (error) {
            console.error(`Failed to set pointer cursor visible, Code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}.`);
          }
        });
    }
  }
}
```

## pointer.setPointerVisible

setPointerVisible(visible: boolean): Promise<void>

设置光标显示/隐藏状态，此状态作用于当前进程的所有窗口。光标在屏幕上的实际显示/隐藏效果还受渲染服务进程影响。使用Promise异步回调。

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

**参数**：

|参数名|类型|必填|说明|
|:------|:------|:-|:--------------------------------|
|visible|boolean|是|当前窗口鼠标光标是否显示。true表示显示，false表示不显示。|

**返回值**：

|类型|说明|
|:------------|:---------------|
|Promise<void>|Promise对象，无返回结果。|

**错误码**：

以下错误码的详细介绍请参见[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:----|:----------------------------------------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|
|801|Capability not supported. 适用版本：18+|

**示例**：

```js
import { pointer } from '@kit.InputKit';
import { BusinessError } from '@kit.BasicServicesKit';

@Entry
@Component
struct Index {
  build() {
    RelativeContainer() {
      Text()
        .onClick(() => {
          try {
            // 设置鼠标指针可见性
            pointer.setPointerVisible(false).then(() => {
              console.info(`Succeeded in setting pointer cursor visible.`);
            }).catch((error: BusinessError) => {
              console.error(`Failed to set pointer cursor, Code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}.`);
            })
          } catch (error) {
            console.error(`Failed to set pointer cursor, Code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}.`);
          }
        })
    }
  }
}
```

## pointer.setPointerVisibleSync^10+^

setPointerVisibleSync(visible: boolean): void

设置光标显示/隐藏状态，此状态作用于当前进程的所有窗口。光标在屏幕上的实际显示/隐藏效果还受渲染服务进程影响。函数调用方式为同步方式。

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

**参数**：

|参数名|类型|必填|说明|
|:------|:------|:-|:--------------------------------|
|visible|boolean|是|当前窗口鼠标光标是否显示。true表示显示，false表示不显示。|

**错误码**：

以下错误码的详细介绍请参见[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:----|:----------------------------------------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|

**示例**：

```js
import { pointer } from '@kit.InputKit';
import { BusinessError } from '@kit.BasicServicesKit';

@Entry
@Component
struct Index {
  build() {
    RelativeContainer() {
      Text()
        .onClick(() => {
          try {
            // 同步设置鼠标指针可见性
            pointer.setPointerVisibleSync(false);
            console.info(`Succeeded in setting pointer cursor visible.`);
          } catch (error) {
            console.error(`Failed to set pointer cursor visible, Code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}.`);
          }
        })
    }
  }
}
```

## pointer.isPointerVisible

isPointerVisible(callback: AsyncCallback<boolean>): void

获取当前窗口的显示/隐藏状态，此状态反映的是多模进程对此窗口所在进程的光标显示/隐藏状态，并非真实的光标显示/隐藏情况，光标是否正确显示/隐藏还受渲染服务进程影响，使用callback异步回调。

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

**参数**：

|参数名|类型|必填|说明|
|:-------|:---------------------|:-|:----------------------------------------------------------------------|
|callback|AsyncCallback<boolean>|是|回调函数。当获取鼠标光标显示状态成功，err为undefined，data为鼠标光标状态（true为显示，false为隐藏）；否则为错误对象。|

**错误码**：

以下错误码的详细介绍请参见[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:----|:----------------------------------------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|

**示例**：

```js
import { pointer } from '@kit.InputKit';
import { BusinessError } from '@kit.BasicServicesKit';

@Entry
@Component
struct Index {
  build() {
    RelativeContainer() {
      Text()
        .onClick(() => {
          try {
            // 查询鼠标指针是否可见
            pointer.isPointerVisible((error: BusinessError, visible: boolean) => {
              if (error) {
                console.error(`Failed to get pointer visible, Code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}.`);
                return;
              }
              console.info(`Succeeded in getting pointer visible, visible: ${JSON.stringify(visible)}.`);
            });
          } catch (error) {
            console.error(`Failed to get pointer visible, Code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}.`);
          }
        })
    }
  }
}
```

## pointer.isPointerVisible

isPointerVisible(): Promise<boolean>

获取当前窗口的显示/隐藏状态，此状态反映的是多模进程对此窗口所在进程的光标显示/隐藏状态，并非真实的光标显示/隐藏情况，光标是否正确显示/隐藏还受渲染服务进程影响，使用Promise异步回调。

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

**返回值**：

|类型|说明|
|:---------------|:----------------------------------------------|
|Promise<boolean>|Promise对象。返回true表示鼠标光标为显示状态；返回false表示鼠标光标为隐藏状态。|

**示例**：

```js
import { pointer } from '@kit.InputKit';
import { BusinessError } from '@kit.BasicServicesKit';

@Entry
@Component
struct Index {
  build() {
    RelativeContainer() {
      Text()
        .onClick(() => {
          try {
            // 查询鼠标指针是否可见
            pointer.isPointerVisible().then((visible: boolean) => {
              console.info(`Succeeded in getting pointer visible, visible: ${JSON.stringify(visible)}.`);
            }).catch((error: BusinessError) => {
              console.error(`Failed to get pointer, Code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}.`);
            })
          } catch (error) {
            console.error(`Failed to get pointer visible, Code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}.`);
          }
        })
    }
  }
}
```

## pointer.isPointerVisibleSync^10+^

isPointerVisibleSync(): boolean

获取当前窗口的显示/隐藏状态，此状态反映的是多模进程对此窗口所在进程的光标显示/隐藏状态，并非真实的光标显示/隐藏情况，光标是否正确显示/隐藏还受渲染服务进程影响，函数调用使用同步方式。

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

**返回值**：

|类型|说明|
|:------|:------------------------------------|
|boolean|返回鼠标光标显示或隐藏状态。true代表显示状态，false代表隐藏状态。|

**示例**：

```js
import { pointer } from '@kit.InputKit';
import { BusinessError } from '@kit.BasicServicesKit';

@Entry
@Component
struct Index {
  build() {
    RelativeContainer() {
      Text()
        .onClick(() => {
          try {
            let visible: boolean = pointer.isPointerVisibleSync();
            console.info(`Succeeded in getting pointer visible, visible: ${JSON.stringify(visible)}.`);
          } catch (error) {
            console.error(`Failed to get pointer visible, Code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}.`);
          }
        })
    }
  }
}
```

## pointer.getPointerStyle

getPointerStyle(windowId: number, callback: AsyncCallback<PointerStyle>): void

获取指定窗口的鼠标样式类型，此接口仅支持获取本应用进程内窗口的鼠标样式类型，使用callback异步回调。

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

**参数**：

|参数名|类型|必填|说明|
|:-------|:-------------------------------------------|:-|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|windowId|number|是|窗口ID。取值范围为大于等于-1的整数，取值为-1时表示全局窗口。 窗口ID合法并且对应窗口存在时，返回窗口的鼠标光标样式。 窗口ID合法但窗口不存在时，默认返回全局鼠标光标样式。 如果通过[setPointerStyle](#pointersetpointerstyle)接口为不存在的窗口设置了鼠标光标样式，使用本接口可以正常获取到该光标样式。|
|callback|AsyncCallback<[PointerStyle](#pointerstyle)>|是|回调函数。当获取鼠标样式类型成功时，err为undefined，data为鼠标样式类型；否则为错误对象。在特定场景（在设置自定义光标样式的窗口上获取样式）下返回DEVELOPER_DEFINED_ICON。|

**错误码**：

以下错误码的详细介绍请参见[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:----|:----------------------------------------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|

**示例**：

```js
import { pointer } from '@kit.InputKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { window } from '@kit.ArkUI';

@Entry
@Component
struct Index {
  build() {
    RelativeContainer() {
      Text()
        .onClick(() => {
          // 获取应用内最近一个窗口
          window.getLastWindow(this.getUIContext().getHostContext(), (error: BusinessError, win: window.Window) => {
            if (error) {
              console.error(`Failed to obtain the top window, Code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}.`);
              return;
            }
            let windowId = win.getWindowProperties().id;
            if (windowId < 0) {
              console.info(`Invalid windowId.`);
              return;
            }
            try {
              // 获取鼠标指针样式
              pointer.getPointerStyle(windowId, (error: BusinessError, style: pointer.PointerStyle) => {
                if (error) {
                  console.error(`Failed to get pointer style, Code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}.`);
                  return;
                }
                console.info(`Succeeded in getting pointer style, style: ${JSON.stringify(style)}.`);
              });
            } catch (error) {
              console.error(`Failed to get pointer style, Code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}.`);
            }
          });
        })
    }
  }
}
```

## pointer.getPointerStyle

getPointerStyle(windowId: number): Promise<PointerStyle>

获取鼠标样式类型，此接口仅支持获取本应用进程内窗口的鼠标样式类型，使用Promise异步回调。

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

**参数**：

|参数名|类型|必填|说明|
|:-------|:-----|:-|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|windowId|number|是|窗口ID。取值范围为大于等于-1的整数，取值为-1时表示全局窗口。 窗口ID合法并且对应窗口存在时，返回窗口的鼠标光标样式。 窗口ID合法但窗口不存在时，默认返回全局鼠标光标样式。 如果通过[setPointerStyle](#pointersetpointerstyle-1)接口为不存在的窗口设置了鼠标光标样式，使用本接口可以正常获取到该光标样式。|

**返回值**：

|类型|说明|
|:-------------------------------------|:------------------|
|Promise<[PointerStyle](#pointerstyle)>|Promise对象，返回鼠标样式类型。|

**错误码**：

以下错误码的详细介绍请参见[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:----|:----------------------------------------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|

**示例**：

```js
import { pointer } from '@kit.InputKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { window } from '@kit.ArkUI';

@Entry
@Component
struct Index {
  build() {
    RelativeContainer() {
      Text()
        .onClick(() => {
          // 获取应用内最近一个窗口
          window.getLastWindow(this.getUIContext().getHostContext(), (error: BusinessError, win: window.Window) => {
            if (error.code) {
              console.error(`Failed to obtain the top window, Code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}.`);
              return;
            }
            let windowId = win.getWindowProperties().id;
            if (windowId < 0) {
              console.info(`Invalid windowId.`);
              return;
            }
            try {
              // 获取鼠标指针样式
              pointer.getPointerStyle(windowId).then((style: pointer.PointerStyle) => {
                console.info(`Succeeded in getting pointer style, style: ${JSON.stringify(style)}.`);
              }).catch((error: BusinessError) => {
                console.error(`Failed to get pointer style, Code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}.`);
              });
            } catch (error) {
              console.error(`Failed to get pointer style, Code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}.`);
            }
          });
        })
    }
  }
}
```

## pointer.getPointerStyleSync^10+^

getPointerStyleSync(windowId: number): PointerStyle

查询指定窗口的鼠标样式类型，如向东箭头、向西箭头、向南箭头、向北箭头等。此接口仅支持获取本应用进程内窗口的鼠标样式类型。

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

**参数**：

|参数名|类型|必填|说明|
|:-------|:-----|:-|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|windowId|number|是|窗口ID。取值范围为大于等于-1的整数，取值为-1时表示全局窗口。 窗口ID合法并且对应窗口存在时，返回窗口的鼠标光标样式。 窗口ID合法但窗口不存在时，默认返回全局鼠标光标样式。 如果通过[setPointerStyleSync](#pointersetpointerstylesync10)接口为不存在的窗口设置了鼠标光标样式，使用本接口可以正常获取到该光标样式。|

**返回值**：

|类型|说明|
|:----------------------------|:--------|
|[PointerStyle](#pointerstyle)|返回鼠标样式类型。|

**错误码**：

以下错误码的详细介绍请参见[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:----|:----------------------------------------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|

**示例**：

```js
import { pointer } from '@kit.InputKit';
import { BusinessError } from '@kit.BasicServicesKit';

@Entry
@Component
struct Index {
  build() {
    RelativeContainer() {
      Text()
        .onClick(() => {
          let windowId = -1;
          try {
            let style: pointer.PointerStyle = pointer.getPointerStyleSync(windowId);
            console.info(`Succeeded in getting pointer style, style: ${JSON.stringify(style)}.`);
          } catch (error) {
            console.error(`Failed to get pointer style, Code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}.`);
          }
        })
    }
  }
}
```

## pointer.setPointerStyle

setPointerStyle(windowId: number, pointerStyle: PointerStyle, callback: AsyncCallback<void>): void

设置指定窗口的鼠标样式类型，此接口仅支持设置本应用进程内窗口的鼠标样式类型，如需通过UIExtensionAbility进程设置宿主窗口的鼠标样式类型，请参阅[setCursor](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/arkts-apis-uicontext-cursorcontroller#setcursor12)，使用callback异步回调。

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

**参数**：

|参数名|类型|必填|说明|
|:-----------|:----------------------------|:-|:---------------------------------------------------------------------------------------------------------------------------------|
|windowId|number|是|窗口ID。取值范围为大于等于0的整数。 窗口ID合法并且对应窗口存在时，可以设置窗口的鼠标光标样式。 窗口ID合法但窗口不存在时，也可以设置鼠标光标样式。 设置结果可通过[getPointerStyle](#pointergetpointerstyle)获取。|
|pointerStyle|[PointerStyle](#pointerstyle)|是|鼠标样式。 不能传入DEVELOPER_DEFINED_ICON作为参数。|
|callback|AsyncCallback<void>|是|回调函数。当设置鼠标样式类型成功，err为undefined，否则为错误对象。|

**错误码**：

以下错误码的详细介绍请参见[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:----|:----------------------------------------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|

**示例**：

```js
import { pointer } from '@kit.InputKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { window } from '@kit.ArkUI';

@Entry
@Component
struct Index {
  build() {
    RelativeContainer() {
      Text()
        .onClick(() => {
          // 获取应用内最近一个窗口
          window.getLastWindow(this.getUIContext().getHostContext(), (error: BusinessError, win: window.Window) => {
            if (error.code) {
              console.error(`Failed to obtain the top window, Code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}.`);
              return;
            }
            let windowId = win.getWindowProperties().id;
            if (windowId < 0) {
              console.info(`Invalid windowId.`);
              return;
            }
            try {
              // 设置鼠标指针样式
              pointer.setPointerStyle(windowId, pointer.PointerStyle.CROSS, error => {
                console.info(`Succeeded in setting pointer style.`);
              });
            } catch (error) {
              console.error(`Failed to set pointer style, Code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}.`);
            }
          });
        })
    }
  }
}
```

## pointer.setPointerStyle

setPointerStyle(windowId: number, pointerStyle: PointerStyle): Promise<void>

设置指定窗口的鼠标样式类型，此接口仅支持设置本应用进程内窗口的鼠标样式类型，如需通过UIExtensionAbility进程设置宿主窗口的鼠标样式类型，请参阅[setCursor](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/arkts-apis-uicontext-cursorcontroller#setcursor12)，使用Promise异步回调。

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

**参数**：

|参数名|类型|必填|说明|
|:-----------|:----------------------------|:-|:-----------------------------------------------------------------------------------------------------------------------------------|
|windowId|number|是|窗口ID。取值范围为大于等于0的整数。 窗口ID合法并且对应窗口存在时，可以设置窗口的鼠标光标样式。 窗口ID合法但窗口不存在时，也可以设置鼠标光标样式。 设置结果可通过[getPointerStyle](#pointergetpointerstyle-1)获取。|
|pointerStyle|[PointerStyle](#pointerstyle)|是|鼠标样式。不能传入DEVELOPER_DEFINED_ICON作为参数。|

**返回值**：

|类型|说明|
|:------------|:---------------|
|Promise<void>|Promise对象，无返回结果。|

**错误码**：

以下错误码的详细介绍请参见[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:----|:----------------------------------------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|

**示例**：

```js
import { pointer } from '@kit.InputKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { window } from '@kit.ArkUI';

@Entry
@Component
struct Index {
  build() {
    RelativeContainer() {
      Text()
        .onClick(() => {
          // 获取应用内最近一个窗口
          window.getLastWindow(this.getUIContext().getHostContext(), (error: BusinessError, win: window.Window) => {
            if (error.code) {
              console.error(`Failed to obtain the top window, Code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}.`);
              return;
            }
            let windowId = win.getWindowProperties().id;
            if (windowId < 0) {
              console.info(`Invalid windowId.`);
              return;
            }
            try {
              // 设置鼠标指针样式
              pointer.setPointerStyle(windowId, pointer.PointerStyle.CROSS).then(() => {
                console.info(`Succeeded in setting pointer style.`);
              }).catch((error: BusinessError) => {
                console.error(`Failed to set pointer style, Code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}.`);
              });
            } catch (error) {
              console.error(`Failed to set pointer style, Code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}.`);
            }
          });
        })
    }
  }
}
```

## pointer.setPointerStyleSync^10+^

setPointerStyleSync(windowId: number, pointerStyle: PointerStyle): void

设置指定窗口的鼠标样式类型，使用同步方式返回结果。此接口仅支持设置本应用进程内窗口的鼠标样式类型，如需通过UIExtensionAbility进程设置宿主窗口的鼠标样式类型，请参阅[setCursor](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/arkts-apis-uicontext-cursorcontroller#setcursor12)。

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

**参数**：

|参数名|类型|必填|说明|
|:-----------|:----------------------------|:-|:-------------------------------------------------------------------------------------------------------------------------------------------|
|windowId|number|是|窗口ID。取值范围为大于等于0的整数。 窗口ID合法并且对应窗口存在时，可以设置窗口的鼠标光标样式。 窗口ID合法但窗口不存在时，也可以设置鼠标光标样式。 设置结果可通过[getPointerStyleSync](#pointergetpointerstylesync10)获取。|
|pointerStyle|[PointerStyle](#pointerstyle)|是|鼠标样式。不能传入DEVELOPER_DEFINED_ICON作为参数。|

**错误码**：

以下错误码的详细介绍请参见[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:----|:----------------------------------------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|

**示例**：

```js
import { pointer } from '@kit.InputKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { window } from '@kit.ArkUI';

@Entry
@Component
struct Index {
  build() {
    RelativeContainer() {
      Text()
        .onClick(() => {
          // 获取应用内最近一个窗口
          window.getLastWindow(this.getUIContext().getHostContext(), (error: BusinessError, win: window.Window) => {
            if (error.code) {
              console.error(`Failed to obtain the top window, Code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}.`);
              return;
            }
            let windowId = win.getWindowProperties().id;
            if (windowId < 0) {
              console.info(`Invalid windowId.`);
              return;
            }
            try {
              // 同步设置鼠标指针样式
              pointer.setPointerStyleSync(windowId, pointer.PointerStyle.CROSS);
              console.info(`Succeeded in setting pointer style.`);
            } catch (error) {
              console.error(`Failed to set pointer style, Code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}.`);
            }
          });
        })
    }
  }
}
```

## PrimaryButton^10+^

鼠标主键类型。

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

|名称|值|说明|
|:----|:-|:----|
|LEFT|0|鼠标左键。|
|RIGHT|1|鼠标右键。|

## RightClickType^10+^

右键菜单的触发方式。

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

|名称|值|说明|
|:-------------------------------------------|:-|:-----------------------|
|TOUCHPAD_RIGHT_BUTTON|1|按压触控板右键区域。|
|TOUCHPAD_LEFT_BUTTON|2|按压触控板左键区域。|
|TOUCHPAD_TWO_FINGER_TAP|3|双指轻击或双指按压触控板。|
|TOUCHPAD_TWO_FINGER_TAP_OR_RIGHT_BUTTON^20+^|4|双指轻击或双指按压触控板、或按压触控板右键区域。|
|TOUCHPAD_TWO_FINGER_TAP_OR_LEFT_BUTTON^20+^|5|双指轻击或双指按压触控板、或按压触控板左键区域。|

## PointerStyle

鼠标光标样式类型。

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

|名称|值|说明|图示|
|:-------------------------------|:---|:---------------------------------------------------------------------------------------------------------------------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|DEFAULT|0|默认|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/99/v3/q7xSRGQ5TH24aUEtTuNthg/zh-cn_image_0000002757233241.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=376205DDF684ADC3AD2AD4B85AE9ED5CEE9A105A3A3C3FCEB322BA528E7C8555)|
|EAST|1|向东箭头|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/6f/v3/5IG5dLNKTa2AcjH72XyayA/zh-cn_image_0000002727593550.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=DEA59AED74EC9D0D50280940BCC1BCDF0F9E4C460FC7D81E2A7A5A20098B1DA6)|
|WEST|2|向西箭头|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/1e/v3/TANEdl7GR2iOvsZXfKlp_w/zh-cn_image_0000002727753408.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=BBCFCBCF66CE1BAA39CC7EF27A6BC94E759014BC066CD9966327820B171993AA)|
|SOUTH|3|向南箭头|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/ae/v3/SbqunuaASa2xOhh8e_VxLg/zh-cn_image_0000002757313123.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=480DC5DEA0E4EDAA9958B96D7FF537C0B7D14386BA28D736206A98D15EBD0CD5)|
|NORTH|4|向北箭头|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/30/v3/CVqlxku5SYmsnWDMQ_qReg/zh-cn_image_0000002757233243.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=DBC61F91C9A18F4EBCEF49ACDE15EFC09A5414EF3E006FE0A2807883E69E90B8)|
|WEST_EAST|5|向西东箭头|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/3c/v3/MEWDQiIWTbqGWDd5jZwZEA/zh-cn_image_0000002727593552.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=D68BDC584C1D326F4B636F0F68152405EC6727560F3AE1FCB0E9AD953FAF98DE)|
|NORTH_SOUTH|6|向北南箭头|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/58/v3/SJIfryL_RlurX2x4d6QMRA/zh-cn_image_0000002727753410.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=9D29B429954F569C982C2978BB17F185FD4022185D6B2B6B852C2156E239E948)|
|NORTH_EAST|7|向东北箭头|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/08/v3/kFQf9VpvTcyI0ntSheH-jA/zh-cn_image_0000002757313125.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=BC1FCAE856516B3827EE9F1592754E163FFF8976CFA40C2E85F612AC00ADB9B1)|
|NORTH_WEST|8|向西北箭头|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/2c/v3/n8wBsZSaQD6gKpbMQRy2MA/zh-cn_image_0000002757233245.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=DD909AC7D88A0FE70A3CCBAC047F8488C368589D77FF926F277267F0464C0293)|
|SOUTH_EAST|9|向东南箭头|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/c9/v3/le_zDHFCS5aBRuXJreLtpQ/zh-cn_image_0000002727593554.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=6B041AA8203C09A4F9B09B104321C1877F0E4EB3DAE0DCC189F0AD7CCC244703)|
|SOUTH_WEST|10|向西南箭头|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/96/v3/bmseF0M8SGuieTpoeO4ktA/zh-cn_image_0000002727753412.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=C75BBB238F4B479591435EC793D86979AB781E0ACA7C10F973DF44404EB10C60)|
|NORTH_EAST_SOUTH_WEST|11|东北西南调整|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/ab/v3/HG_PwFq_RKWduYJZUV5IBQ/zh-cn_image_0000002757313127.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=68227DCEB8BD46028D3D4A9768946D6C304047FED057216F6FBD48048AB1397B)|
|NORTH_WEST_SOUTH_EAST|12|西北东南调整|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/d5/v3/DfsXWd6_SUKKA0st7jvXPA/zh-cn_image_0000002757233247.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=28C51437C99899634BD07E50BF86603446395ED2313D0853D33A1E8D04D121E4)|
|CROSS|13|准确选择|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/1d/v3/BM_EqJD8Tl2uFdbQKhjFSQ/zh-cn_image_0000002727593556.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=B8606BAED91A032B30ED046C582D4E2D4F298C74F2DE90BC4D7C5FA0B1C3337E)|
|CURSOR_COPY|14|复制|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/fd/v3/cy9u0HNPRkme5CwpWqefcA/zh-cn_image_0000002727753414.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=9A0C3B62936C6C7C97C2242C1CE35CF34153F6190DA012192590890C725C1C15)|
|CURSOR_FORBID|15|不可用|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/9f/v3/_GjT8a5MS4C2pmZtVfompg/zh-cn_image_0000002757313129.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=846699679D74E01A89E23D52F36A59970179A8561A03AD29600EAE523D25CAD4)|
|COLOR_SUCKER|16|取色器|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/60/v3/btNxE1XQTkWqghFij1trrw/zh-cn_image_0000002757233249.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=45643176321978609E5E9B11B9F42F7AD8F35655AEE858271AAC0D06CC696EAB)|
|HAND_GRABBING|17|并拢的手|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/19/v3/95RIuidmTJasAQgzOGCMkg/zh-cn_image_0000002727593558.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=3B1F781CFE4679BF1C13637A123274743C5AD91BC4E802D7B3598BC397303A7F)|
|HAND_OPEN|18|张开的手|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/63/v3/K4B4Yw9KT7-kwKEwt7p9lQ/zh-cn_image_0000002727753416.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=694D2B43821B4A05FCBB2C1EF3E2055E4448322D4E6CA1365641C5C4A2D58E71)|
|HAND_POINTING|19|手形指针|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/26/v3/DYvQHog5R-ioCMmqLMl9mQ/zh-cn_image_0000002757313131.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=C568E9FE43E69C22C5327402F4C9A58DBC62546883A20665AF877C78108032D0)|
|HELP|20|帮助选择|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/87/v3/QBK7VpHQT8eaIXbim26uzg/zh-cn_image_0000002757233251.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=C5FE29CAF1BD708D7CF3F138E0D790E3D718094D8E93C31D5B0DBC86411999F2)|
|MOVE|21|移动|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/a1/v3/23zL0S5SS9q48gXZ1V9fPQ/zh-cn_image_0000002727593560.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=72D8BF47B9E04808AE6B43FA2771E90A417D135D424D4ED5EB2BEA4850711883)|
|RESIZE_LEFT_RIGHT|22|内部左右调整|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/f2/v3/95aQJ85SSi2mzTCK62lvVw/zh-cn_image_0000002727753418.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=D1E180715EA2189461B1DA77461C5C8B6AB85515B9694F2DF0C47986E3D477E6)|
|RESIZE_UP_DOWN|23|内部上下调整|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/ed/v3/NrVlV_q4TJquegny-TFkMA/zh-cn_image_0000002757313133.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=C3633787C9D243F0F3985A3288490ACED39AAD6E4A4FCAAD0AAB7BE8DB32FAF4)|
|SCREENSHOT_CHOOSE|24|截图十字准星|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/86/v3/UiV3lSu8R2CJvi0rOHE1WA/zh-cn_image_0000002757233253.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=7C7CDDA81DA0027F31E1947713CDDC4387B601CDFD0AE11ACD2DF257D710D19A)|
|SCREENSHOT_CURSOR|25|截图|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/8/v3/CCacfq2gSuCuPZJ5Wrf_HQ/zh-cn_image_0000002727593562.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=22FC842E0AB24392493A634B798AFA724EF2CBD5006671AAE5133A8EF8A947A1)|
|TEXT_CURSOR|26|文本选择|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/f7/v3/5qvQrZizRTOs1ecg-JIlhQ/zh-cn_image_0000002727753420.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=B59ED7743DFFBC05F3F91001746BE25C770EC516C9A59CA27F6F6CAB11C1D0B7)|
|ZOOM_IN|27|放大|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/8a/v3/kPD18_9kQ22M0MaoiIT9Tg/zh-cn_image_0000002757313135.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=C38E368DF00E51B9270FDCAB0DAF0DBEF0BCBF0E8A2CA30F1FCEE1AFA44125BC)|
|ZOOM_OUT|28|缩小|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/78/v3/haq-wEn8S7qR7c4FFnP67Q/zh-cn_image_0000002757233255.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=5FD09971209E43F6481DF853D6644E861FF5310EFFF2E2873353A157726AF32B)|
|MIDDLE_BTN_EAST|29|向东滚动|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/bd/v3/ow-QssTOSO-5VV8LP5Uxaw/zh-cn_image_0000002727593564.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=431A390515BDA8C89F97B95D29DD77E95DD920BC36696BCA69114C7D0AA52C94)|
|MIDDLE_BTN_WEST|30|向西滚动|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/f2/v3/ssD-7VI0SbuY2eyPwyOkIQ/zh-cn_image_0000002727753422.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=EEA3EB4ED838ABA23CD0D48E8D9446D203FE65CF5F8BDFA81CE9692C6E5E3424)|
|MIDDLE_BTN_SOUTH|31|向南滚动|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/5e/v3/hPJ_S652QPu0w3Mog30XRg/zh-cn_image_0000002757313137.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=3B76CE3724BAD7D6B9EEE53FD81A9264C6CF35BEE220F45B5119C8C23433315C)|
|MIDDLE_BTN_NORTH|32|向北滚动|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/f3/v3/99wqrTV2RXys5sssEoL_Gg/zh-cn_image_0000002757233257.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=646AE6CC569FDD3D5DCA5890AD60154562E9CE314A21BD0DAD1B837675D93740)|
|MIDDLE_BTN_NORTH_SOUTH|33|向南北滚动|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/78/v3/tnea5QsCQjeWaLS4xARyHw/zh-cn_image_0000002727593566.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=7F4D1944821D483C975DED2914AD461E47792E32928EAD2F0E29D10F2A3A5858)|
|MIDDLE_BTN_NORTH_EAST|34|向东北滚动|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/96/v3/8Pk1nbttTiqoUvrvme13Ug/zh-cn_image_0000002727753424.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=D5028A6CC0C374597C0247A755812B3B6CCC6A5FF6DB78261E87819542CEEC10)|
|MIDDLE_BTN_NORTH_WEST|35|向西北滚动|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/b8/v3/4ZanG27ATlip7LI_A2B9Yw/zh-cn_image_0000002757313139.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=BD26B05051A2E50A9312610E1A97EA6D002C2A698AEA4D0914605B7893923B52)|
|MIDDLE_BTN_SOUTH_EAST|36|向东南滚动|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/e9/v3/wx3pBRJCRe24RE1xcgNEYQ/zh-cn_image_0000002757233259.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=724C0DD36AC849697402DFDEC58F5A27DC193CC768CDE71FD5611A2C1ABA0A7B)|
|MIDDLE_BTN_SOUTH_WEST|37|向西南滚动|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/e4/v3/2LETfKwkSreICwc7DOZABg/zh-cn_image_0000002727593568.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=F42EB153E1E2A9209095BD02F3BDB956CF67822DAA1123A1B1912337DD01352E)|
|MIDDLE_BTN_NORTH_SOUTH_WEST_EAST|38|四向锥形移动|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/f0/v3/PKItwoleQriUJ51jN-Nnnw/zh-cn_image_0000002727753426.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=56389FF6489849BA370A9940ECD13675FA96C3F835DD92B17B4DA292572ABE85)|
|HORIZONTAL_TEXT_CURSOR^10+^|39|水平文本选择|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/13/v3/5k3WlLlNSUadOT23O-5YWA/zh-cn_image_0000002757313141.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=072D914986CBF8BE2B404662D1966DE1B68A3EDFCDCB8626478BB1E096686CB1)|
|CURSOR_CROSS^10+^|40|十字光标|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/89/v3/5Uwrb40pSsmcHoQRDojI-A/zh-cn_image_0000002757233261.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=8A5987248C57B20482A178D16F31BA1FD16FD85EE411A9F6F1DB12BFB88E3C19)|
|CURSOR_CIRCLE^10+^|41|圆形光标|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/d5/v3/mclUo33kTkKvlxD96_tFuQ/zh-cn_image_0000002727593570.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=E5D9B331B8A47131709B4E3C5063BA3EF5B79AE0501D44B9EEA08922C0A6F0B1)|
|LOADING^10+^|42|正在载入动画光标 **元服务API：** 从API version 12开始，该接口支持在元服务中使用。|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/42/v3/yZdqHcecTVGIAQ2JFUjQ8Q/zh-cn_image_0000002727753428.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=453E5E269E4524C4083F97C1134AE1D5392E08FD5C80F878F6F0DA81F97BF61D)|
|RUNNING^10+^|43|后台运行中动画光标 **元服务API：** 从API version 12开始，该接口支持在元服务中使用。|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/36/v3/TMSRMaToTdWqhLzOGtkrIA/zh-cn_image_0000002757313143.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=F0710D572151E7A8EBF1D52B1F5FB5E7E28D3E5DF010C8246CB21A564D7D23D5)|
|MIDDLE_BTN_EAST_WEST^18+^|44|向东西滚动|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/3f/v3/G8X7Kl9cSoSZTt-umujqmw/zh-cn_image_0000002757233263.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=15625E5A3224FA254CCE6D0DE40008E47A8A4EED6A77A9D54B4B70D5236BC28F)|
|RUNNING_LEFT^22+^|45|后台运行中动画光标（拓展1）|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/12/v3/0HdV_GccRB-JBlXOav5lAg/zh-cn_image_0000002727593572.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=EF7E614BF1AB40AFEB7E60A308B2A2C714F70702E9634120D0E008E0572E8633)|
|RUNNING_RIGHT^22+^|46|后台运行中动画光标（拓展2）|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/b0/v3/wsDdtborTN6ZdmGK7orYxQ/zh-cn_image_0000002727753430.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=5C931E05F6A50596580FAD8E62E7C7AF0D17C0E160C0625E2DA6EB3EAC8B18A1)|
|AECH_DEVELOPER_DEFINED_ICON^22+^|47|圆形自定义光标|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/a7/v3/YjxwjPsETlOAf01u_R0Vyg/zh-cn_image_0000002757313145.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=3C76345C59D0E75C58A810689E18935C713B8C8AF8CDB32EFB49AAD42ED5C879)|
|SCREENRECORDER_CURSOR^20+^|48|录屏光标|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/3f/v3/0Ph1hejRQNGa4G1_sCu0iw/zh-cn_image_0000002757233265.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=4CD150B6B19AF960881023523CC13F42213421D84DFE42CD216A16D9DB7C0417)|
|LASER_CURSOR^22+^|49|悬浮光标。手写笔进入空鼠模式时使用该光标，无法直接设置。 空鼠模式支持通过手写笔在空中转动来控制屏幕上虚拟光标的移动，并借助笔身按键实现上下翻页功能，用于演示PPT、隔空操作等场景。|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/d8/v3/6zo3VtKvTX2P3ZyoAZvEqQ/zh-cn_image_0000002727593574.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=F6456AE8B30D909157F00AE2B55EC33C15CAEBAA23C9FDF4BABE37BC5D7C9F4C)|
|LASER_CURSOR_DOT^22+^|50|点击光标。手写笔进入空鼠模式时使用该光标，无法直接设置。 空鼠模式支持通过手写笔在空中转动来控制屏幕上虚拟光标的移动，并借助笔身按键实现上下翻页功能，用于演示PPT、隔空操作等场景。|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/82/v3/48UgBPSBRX6WBeKfx9c6kA/zh-cn_image_0000002727753432.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=15E0535536AE8F766C79D11C752BA147B804AAF64C0EE647E6FDF68249B52C9B)|
|LASER_CURSOR_DOT_RED^22+^|51|激光笔光标。手写笔进入空鼠模式时使用该光标，无法直接设置。 空鼠模式支持通过手写笔在空中转动来控制屏幕上虚拟光标的移动，并借助笔身按键实现上下翻页功能，用于演示PPT、隔空操作等场景。|![](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_scene_100_1/ad/v3/va9YmP0HR2OiRnFEwRkGVQ/zh-cn_image_0000002757313147.png?HW-CC-KV=V1&HW-CC-Date=20260915T034246Z&HW-CC-Expire=31536000000&HW-CC-Sign=C0F49C6BA249F0E202E89AC0F9C89704C18B9781CCCBC262F3E4CB0E3FBD9841)|
|DEVELOPER_DEFINED_ICON^22+^|-100|自定义光标，开发者可使用[setCustomCursor](#pointersetcustomcursor15)设置自定义光标，不支持使用[setPointerStyle](#pointersetpointerstyle-1)直接设置。|自定义光标样式，通过接口设置。该参数用于getPointerStyle在特定场景（在设置自定义光标样式的窗口上获取样式）下返回数据，不能作为setCustomCursor、setPointerStyle接口入参使用。|

## pointer.setCustomCursor^11+^

setCustomCursor(windowId: number, pixelMap: image.PixelMap, focusX?: number, focusY?: number): Promise<void>

设置指定窗口的自定义光标样式，此接口仅支持设置本应用进程内窗口的自定义光标样式，如需通过UIExtensionAbility进程设置宿主窗口的自定义光标样式，请参阅[setCustomCursor](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/arkts-apis-uicontext-cursorcontroller#setcustomcursor)，使用Promise异步回调。

应用窗口布局改变、热区切换、页面跳转、光标移出再回到窗口、光标在窗口不同区域移动，以上场景可能导致光标切换回系统样式，需要开发者重新设置光标样式。

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

**参数**：

|参数名|类型|必填|说明|
|:-------|:------------------------------------------------------------------------------------------------------------|:-|:----------------------------------|
|windowId|number|是|窗口ID。取值为大于0的整数。|
|pixelMap|[image.PixelMap](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/arkts-apis-image-pixelmap)|是|自定义光标资源。|
|focusX|number|否|自定义光标焦点x，取值范围：大于等于0，默认为0，单位为像素（px）。|
|focusY|number|否|自定义光标焦点y，取值范围：大于等于0，默认为0，单位为像素（px）。|

**返回值**：

|类型|说明|
|:------------|:---------------|
|Promise<void>|Promise对象，无返回结果。|

**错误码**：

以下错误码的详细介绍请参见[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:----|:----------------------------------------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|

**示例**：

```js
import { pointer } from '@kit.InputKit';
import { image } from '@kit.ImageKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { window } from '@kit.ArkUI';

@Entry
@Component
struct Index {
  build() {
    RelativeContainer() {
      Text()
        .onClick(() => {
          // app_icon为示例资源，请开发者根据实际需求配置资源文件。
          this.getUIContext()?.getHostContext()?.resourceManager.getMediaContent(
            $r('app.media.app_icon').id, (error: BusinessError, svgFileData: Uint8Array) => {
            const svgBuffer: ArrayBuffer = svgFileData.buffer.slice(0);
            let svgImageSource: image.ImageSource = image.createImageSource(svgBuffer);
            let svgDecodingOptions: image.DecodingOptions = { desiredSize: { width: 50, height: 50 } };
            // 创建PixelMap
            svgImageSource.createPixelMap(svgDecodingOptions).then((pixelMap) => {
              window.getLastWindow(this.getUIContext().getHostContext(), (error: BusinessError, win: window.Window) => {
                let windowId = win.getWindowProperties().id;
                try {
                  pointer.setCustomCursor(windowId, pixelMap).then(() => {
                    console.info(`Succeeded in setting custom cursor.`);
                  });
                } catch (error) {
                  console.error(`Failed to set custom cursor, Code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}.`);
                }
              });
            }).catch((error: BusinessError) => {
                console.error(`Failed to create pixel map promise, Code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}.`);
              });
          });
        })
    }
  }
}
```

## CustomCursor^15+^

自定义光标资源。

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

|名称|类型|只读|可选|说明|
|:-------|:------------------------------------------------------------------------------------------------------------|:-|:-|:--------------------------------------------------------------------|
|pixelMap|[image.PixelMap](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/arkts-apis-image-pixelmap)|否|否|自定义光标。最小限制为资源图本身的最小限制。最大限制为256 x 256px。|
|focusX|number|否|是|自定义光标焦点的水平坐标。该坐标受自定义光标大小的限制。最小值为0，最大值为资源图的宽度最大值，该参数缺省时默认为0，单位为像素（px）。|
|focusY|number|否|是|自定义光标焦点的垂直坐标。该坐标受自定义光标大小的限制。最小值为0，最大值为资源图的高度最大值，该参数缺省时默认为0，单位为像素（px）。|

## CursorConfig^15+^

自定义光标配置。

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

|名称|类型|只读|可选|说明|
|:-----------|:------|:-|:-|:------------------------------------------------------------------------------|
|followSystem|boolean|否|否|是否根据系统设置调整光标大小。false表示使用自定义光标样式大小，true表示根据系统设置调整光标大小，可调整范围为：[光标资源图大小, 256×256]。|

## pointer.setCustomCursor^15+^

setCustomCursor(windowId: number, cursor: CustomCursor, config: CursorConfig): Promise<void>

设置指定窗口的自定义光标样式，此接口仅支持设置本应用进程内窗口的自定义光标样式，如需通过UIExtensionAbility进程设置宿主窗口的自定义光标样式，请参阅[setCustomCursor](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/arkts-apis-uicontext-cursorcontroller#setcustomcursor)，使用Promise异步回调。

应用窗口布局改变、热区切换、页面跳转、光标移出再回到窗口、光标在窗口不同区域移动，以上场景可能导致光标切换回系统样式，需要开发者重新设置光标样式。

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

**参数**：

|参数名|类型|必填|说明|
|:-------|:------------------------------|:-|:---------------------------------------------------------------------------------------------|
|windowId|number|是|窗口ID。取值为大于0的整数。|
|cursor|[CustomCursor](#customcursor15)|是|自定义光标资源。|
|config|[CursorConfig](#cursorconfig15)|是|自定义光标配置，用于配置是否根据系统设置调整光标大小。如果CursorConfig中followSystem设置为true，则光标大小的可调整范围为：[光标资源图大小, 256×256]。|

**返回值**：

|类型|说明|
|:------------|:---------------|
|Promise<void>|Promise对象，无返回结果。|

**错误码**：

以下错误码的详细介绍请参见[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)和[鼠标光标错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-pointer)。

|错误码ID|错误信息|
|:-------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Abnormal windowId parameter passed in. 2. Abnormal pixelMap parameter passed in; 3. Abnormal focusX parameter passed in.4. Abnormal focusY parameter passed in.|
|26500001|Invalid windowId. Possible causes: The window id does not belong to the current process.|

**示例**：

```js
import { pointer } from '@kit.InputKit';
import { image } from '@kit.ImageKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { window } from '@kit.ArkUI';

@Entry
@Component
struct Index {
  build() {
    RelativeContainer() {
      Text()
        .onClick(() => {
          // app_icon为示例资源，请开发者根据实际需求配置资源文件。
          this.getUIContext()?.getHostContext()?.resourceManager.getMediaContent(
            $r('app.media.app_icon').id, (error: BusinessError, svgFileData: Uint8Array) => {
            const svgBuffer: ArrayBuffer = svgFileData.buffer.slice(0);
            let svgImageSource: image.ImageSource = image.createImageSource(svgBuffer);
            let svgDecodingOptions: image.DecodingOptions = { desiredSize: { width: 50, height: 50 } };
            // 创建PixelMap
            svgImageSource.createPixelMap(svgDecodingOptions).then((pixelMap) => {
              // 获取应用内最近一个窗口
              window.getLastWindow(this.getUIContext().getHostContext(), (error: BusinessError, win: window.Window) => {
                let windowId = win.getWindowProperties().id;
                try {
                  // 设置自定义光标
                  pointer.setCustomCursor(windowId, { pixelMap: pixelMap, focusX: 25, focusY: 25 },
                    { followSystem: false }).then(() => {
                    console.info(`Succeeded in setting custom cursor.`);
                  });
                } catch (error) {
                  console.error(`Failed to set custom cursor, Code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}.`);
                }
              });
            }).catch((error: BusinessError) => {
                console.error(`Failed to create pixel map promise, Code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}.`);
              });
          });
        })
    }
  }
}
```

## pointer.setCustomCursorSync^11+^

setCustomCursorSync(windowId: number, pixelMap: image.PixelMap, focusX?: number, focusY?: number): void

设置指定窗口的自定义光标样式，使用同步方式进行设置。此接口仅支持设置本应用进程内窗口的自定义光标样式，如需通过UIExtensionAbility进程设置宿主窗口的自定义光标样式，请参阅[setCustomCursor](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/arkts-apis-uicontext-cursorcontroller#setcustomcursor)。

应用窗口布局改变、热区切换、页面跳转、光标移出再回到窗口、光标在窗口不同区域移动，以上场景可能导致光标切换回系统样式，需要开发者重新设置光标样式。

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

**参数**：

|参数名|类型|必填|说明|
|:-------|:------------------------------------------------------------------------------------------------------------|:-|:----------------------------------|
|windowId|number|是|窗口ID。取值为大于0的整数。|
|pixelMap|[image.PixelMap](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/arkts-apis-image-pixelmap)|是|自定义光标资源。|
|focusX|number|否|自定义光标焦点x，取值范围：大于等于0，默认为0，单位为像素（px）。|
|focusY|number|否|自定义光标焦点y，取值范围：大于等于0，默认为0，单位为像素（px）。|

**错误码**：

以下错误码的详细介绍请参见[通用错误码](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/errorcode-universal)。

|错误码ID|错误信息|
|:----|:----------------------------------------------------------------------------------------------------------------------------------------------|
|401|Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.|

**示例**：

```js
import { pointer } from '@kit.InputKit';
import { image } from '@kit.ImageKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { window } from '@kit.ArkUI';

@Entry
@Component
struct Index {
  build() {
    RelativeContainer() {
      Text()
        .onClick(() => {
          // app_icon为示例资源，请开发者根据实际需求配置资源文件。
          this.getUIContext()?.getHostContext()?.resourceManager.getMediaContent(
            $r('app.media.app_icon').id, (error: BusinessError, svgFileData: Uint8Array) => {
            const svgBuffer = svgFileData.buffer;
            let svgImageSource: image.ImageSource = image.createImageSource(svgBuffer);
            // 光标图片宽高
            let svgDecodingOptions: image.DecodingOptions = { desiredSize: { width: 50, height: 50 } };
            // 创建PixelMap
            svgImageSource.createPixelMap(svgDecodingOptions).then((pixelMap) => {
              // 获取应用内最近一个窗口
              window.getLastWindow(this.getUIContext().getHostContext(), (error: BusinessError, win: window.Window) => {
                let windowId = win.getWindowProperties().id;
                try {
                  // 同步设置自定义光标
                  pointer.setCustomCursorSync(windowId, pixelMap, 25, 25);
                  console.info(`Succeeded in setting custom cursor sync.`);
                } catch (error) {
                  console.error(`Failed to set custom cursor sync, Code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}.`);
                }
              });
            }).catch((error: BusinessError) => {
              console.error(`Failed to create pixel map promise, Code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message}.`);
            });
          });
        }
      )
    }
  }
}
```

