# @ohos.multimodalInput.pointer (鼠标指针) 鼠标指针管理模块,用于查询和设置鼠标指针相关属性。 > **说明**: > > 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 ## 导入模块 ```js import { pointer } from '@kit.InputKit'; ``` ## pointer.setPointerVisible setPointerVisible(visible: boolean, callback: AsyncCallback<void>): void 设置鼠标指针显示或者隐藏,使用AsyncCallback异步方式返回结果。 **系统能力**:SystemCapability.MultimodalInput.Input.Pointer **参数**: | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------------------------------------- | | visible | boolean | 是 | 鼠标指针是否显示。true表示显示,false表示不显示。 | | callback | AsyncCallback<void> | 是 | 回调函数。 | **错误码**: 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 | 错误码ID | 错误信息 | | ---- | --------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | | 801 | Capability not supported. | **示例**: ```js try { pointer.setPointerVisible(true, (error: Error) => { if (error) { console.log(`Set pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`); return; } console.log(`Set pointer visible success`); }); } catch (error) { console.log(`Set pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`); } ``` ## pointer.setPointerVisible setPointerVisible(visible: boolean): Promise<void> 设置鼠标指针显示或者隐藏,使用Promise异步方式返回结果。 **系统能力**:SystemCapability.MultimodalInput.Input.Pointer **参数**: | 参数名 | 类型 | 必填 | 说明 | | ------- | ------- | ---- | ---------------------------------------- | | visible | boolean | 是 | 鼠标指针是否显示。true表示显示,false表示不显示。 | **返回值**: | 参数 | 说明 | | ------------------- | ------------------- | | Promise<void> | Promise对象。 | **错误码**: 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 | 错误码ID | 错误信息 | | ---- | --------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | | 801 | Capability not supported. | **示例**: ```js try { pointer.setPointerVisible(false).then(() => { console.log(`Set pointer visible success`); }); } catch (error) { console.log(`Set pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`); } ``` ## pointer.setPointerVisibleSync10+ setPointerVisibleSync(visible: boolean): void 使用同步方式设置鼠标指针显示或者隐藏。 **系统能力**:SystemCapability.MultimodalInput.Input.Pointer **参数**: | 参数名 | 类型 | 必填 | 说明 | | ------- | ------- | ---- | ---------------------------------------- | | visible | boolean | 是 | 鼠标指针是否显示。true表示显示,false表示不显示。 | **错误码**: 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 | 错误码ID | 错误信息 | | ---- | --------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | **示例**: ```js try { pointer.setPointerVisibleSync(false); console.log(`Set pointer visible success`); } catch (error) { console.log(`Set pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`); } ``` ## pointer.isPointerVisible isPointerVisible(callback: AsyncCallback<boolean>): void 获取鼠标指针显示或隐藏状态,使用AsyncCallback异步方式返回结果。 **系统能力**:SystemCapability.MultimodalInput.Input.Pointer **参数**: | 参数名 | 类型 | 必填 | 说明 | | -------- | ---------------------------- | ---- | -------------- | | callback | AsyncCallback<boolean> | 是 | 回调函数,异步返回鼠标指针状态,true为显示,false为隐藏。 | **错误码**: 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 | 错误码ID | 错误信息 | | ---- | --------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | **示例**: ```js try { pointer.isPointerVisible((error: Error, visible: boolean) => { if (error) { console.log(`Get pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`); return; } console.log(`Get pointer visible success, visible: ${JSON.stringify(visible)}`); }); } catch (error) { console.log(`Get pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`); } ``` ## pointer.isPointerVisible isPointerVisible(): Promise<boolean> 获取鼠标指针显示或隐藏状态,使用Promise异步方式返回结果。 **系统能力**:SystemCapability.MultimodalInput.Input.Pointer **返回值**: | 参数 | 说明 | | ---------------------- | ------------------- | | Promise<boolean> | Promise对象,异步返回鼠标指针显示或隐藏状态。true代表显示状态,false代表隐藏状态。 | **示例**: ```js try { pointer.isPointerVisible().then((visible: boolean) => { console.log(`Get pointer visible success, visible: ${JSON.stringify(visible)}`); }); } catch (error) { console.log(`Get pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`); } ``` ## pointer.isPointerVisibleSync10+ isPointerVisibleSync(): boolean 使用同步方式获取鼠标指针显示或者隐藏。 **系统能力**:SystemCapability.MultimodalInput.Input.Pointer **返回值**: | 参数 | 说明 | | ---------------------- | ------------------- | | boolean | 返回鼠标指针显示或隐藏状态。true代表显示状态,false代表隐藏状态。 | **示例**: ```js try { let visible: boolean = pointer.isPointerVisibleSync(); console.log(`Get pointer visible success, visible: ${JSON.stringify(visible)}`); } catch (error) { console.log(`Get pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`); } ``` ## pointer.getPointerStyle getPointerStyle(windowId: number, callback: AsyncCallback<PointerStyle>): void 获取鼠标样式类型,使用AsyncCallback异步方式返回结果。 **系统能力**:SystemCapability.MultimodalInput.Input.Pointer **参数**: | 参数名 | 类型 | 必填 | 说明 | | -------- | ---------------------------------------- | ---- | -------------- | | windowId | number | 是 | 窗口id。 | | callback | AsyncCallback<[PointerStyle](#pointerstyle)> | 是 | 回调函数,异步返回鼠标样式类型。 | **错误码**: 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 | 错误码ID | 错误信息 | | ---- | --------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | **示例**: ```js import { BusinessError } from '@kit.BasicServicesKit'; import { window } from '@kit.ArkUI'; window.getLastWindow(this.getUIContext().getHostContext(), (error: BusinessError, win: window.Window) => { if (error.code) { console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(error)); return; } let windowId = win.getWindowProperties().id; if (windowId < 0) { console.log(`Invalid windowId`); return; } try { pointer.getPointerStyle(windowId, (error: Error, style: pointer.PointerStyle) => { console.log(`Get pointer style success, style: ${JSON.stringify(style)}`); }); } catch (error) { console.log(`Get pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`); } }); ``` ## pointer.getPointerStyle getPointerStyle(windowId: number): Promise<PointerStyle> 获取鼠标样式类型,使用Promise异步方式返回结果。 **系统能力**:SystemCapability.MultimodalInput.Input.Pointer **参数**: | 参数名 | 类型 | 必填 | 说明 | | -------- | ------ | ---- | -------- | | windowId | number | 是 | 窗口id。 | **返回值**: | 参数 | 说明 | | ---------------------------------------- | ------------------- | | Promise<[PointerStyle](#pointerstyle)> | Promise实例,异步返回鼠标样式类型。 | **错误码**: 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 | 错误码ID | 错误信息 | | ---- | --------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | **示例**: ```js import { BusinessError } from '@kit.BasicServicesKit'; import { window } from '@kit.ArkUI'; window.getLastWindow(this.getUIContext().getHostContext(), (error: BusinessError, win: window.Window) => { if (error.code) { console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(error)); return; } let windowId = win.getWindowProperties().id; if (windowId < 0) { console.log(`Invalid windowId`); return; } try { pointer.getPointerStyle(windowId).then((style: pointer.PointerStyle) => { console.log(`Get pointer style success, style: ${JSON.stringify(style)}`); }); } catch (error) { console.log(`Get pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`); } }); ``` ## pointer.getPointerStyleSync10+ getPointerStyleSync(windowId: number): PointerStyle 使用同步方式获取鼠标样式类型。 **系统能力**:SystemCapability.MultimodalInput.Input.Pointer **参数**: | 参数名 | 类型 | 必填 | 说明 | | -------- | ------ | ---- | -------- | | windowId | number | 是 | 窗口id。
默认值为-1,表示获取全局的鼠标样式。 | **返回值**: | 参数 | 说明 | | ---------------------------------------- | ------------------- | | [PointerStyle](#pointerstyle) | 返回鼠标样式类型。 | **错误码**: 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 | 错误码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'; let windowId = -1; try { let style: pointer.PointerStyle = pointer.getPointerStyleSync(windowId); console.log(`Get pointer style success, style: ${JSON.stringify(style)}`); } catch (error) { console.log(`Get pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`); } ``` ## pointer.setPointerStyle setPointerStyle(windowId: number, pointerStyle: PointerStyle, callback: AsyncCallback<void>): void 设置鼠标样式类型,使用AsyncCallback异步方式返回结果。 **系统能力**:SystemCapability.MultimodalInput.Input.Pointer **参数**: | 参数名 | 类型 | 必填 | 说明 | | ------------ | ------------------------------ | ---- | ----------------------------------- | | windowId | number | 是 | 窗口id。 | | pointerStyle | [PointerStyle](#pointerstyle) | 是 | 鼠标样式。 | | callback | AsyncCallback<void> | 是 | 回调函数。 | **错误码**: 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 | 错误码ID | 错误信息 | | ---- | --------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | **示例**: ```js import { BusinessError } from '@kit.BasicServicesKit'; import { window } from '@kit.ArkUI'; window.getLastWindow(this.getUIContext().getHostContext(), (error: BusinessError, win: window.Window) => { if (error.code) { console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(error)); return; } let windowId = win.getWindowProperties().id; if (windowId < 0) { console.log(`Invalid windowId`); return; } try { pointer.setPointerStyle(windowId, pointer.PointerStyle.CROSS, error => { console.log(`Set pointer style success`); }); } catch (error) { console.log(`Set pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`); } }); ``` ## pointer.setPointerStyle setPointerStyle(windowId: number, pointerStyle: PointerStyle): Promise<void> 设置鼠标样式类型,使用Promise异步方式返回结果。 **系统能力**:SystemCapability.MultimodalInput.Input.Pointer **参数**: | 参数名 | 类型 | 必填 | 说明 | | ------------------- | ------------------------------ | ---- | ---------------- | | windowId | number | 是 | 窗口id。 | | pointerStyle | [PointerStyle](#pointerstyle) | 是 | 鼠标样式。 | **返回值**: | 参数 | 说明 | | ------------------- | ------------------- | | Promise<void> | Promise对象。 | **错误码**: 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 | 错误码ID | 错误信息 | | ---- | --------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | **示例**: ```js import { BusinessError } from '@kit.BasicServicesKit'; import { window } from '@kit.ArkUI'; window.getLastWindow(this.getUIContext().getHostContext(), (error: BusinessError, win: window.Window) => { if (error.code) { console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(error)); return; } let windowId = win.getWindowProperties().id; if (windowId < 0) { console.log(`Invalid windowId`); return; } try { pointer.setPointerStyle(windowId, pointer.PointerStyle.CROSS).then(() => { console.log(`Set pointer style success`); }); } catch (error) { console.log(`Set pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`); } }); ``` ## pointer.setPointerStyleSync10+ setPointerStyleSync(windowId: number, pointerStyle: PointerStyle): void 使用同步方式设置鼠标样式类型。 **系统能力**:SystemCapability.MultimodalInput.Input.Pointer **参数**: | 参数名 | 类型 | 必填 | 说明 | | ------------------- | ------------------------------ | ---- | ---------------- | | windowId | number | 是 | 窗口id。 | | pointerStyle | [PointerStyle](#pointerstyle) | 是 | 鼠标样式。 | **错误码**: 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 | 错误码ID | 错误信息 | | ---- | --------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | **示例**: ```js import { BusinessError } from '@kit.BasicServicesKit'; import { window } from '@kit.ArkUI'; window.getLastWindow(this.getUIContext().getHostContext(), (error: BusinessError, win: window.Window) => { if (error.code) { console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(error)); return; } let windowId = win.getWindowProperties().id; if (windowId < 0) { console.log(`Invalid windowId`); return; } try { pointer.setPointerStyleSync(windowId, pointer.PointerStyle.CROSS); console.log(`Set pointer style success`); } catch (error) { console.log(`getPointerSize failed, error: ${JSON.stringify(error, [`code`, `message`])}`); } }); ``` ## PrimaryButton10+ 鼠标主键类型。 **系统能力**:SystemCapability.MultimodalInput.Input.Pointer | 名称 | 值 | 说明 | | -------------------------------- | ---- | ------ | | LEFT | 0 | 鼠标左键。 | | RIGHT | 1 | 鼠标右键。 | ## RightClickType10+ 右键菜单触发方式。 **系统能力**:SystemCapability.MultimodalInput.Input.Pointer | 名称 | 值 | 说明 | | -------------------------------- | ---- | ------ | | TOUCHPAD_RIGHT_BUTTON | 1 |触控板右键区域。 | | TOUCHPAD_LEFT_BUTTON | 2 |触控板左键区域。 | | TOUCHPAD_TWO_FINGER_TAP | 3 |双指轻击或按压触控板。| ## PointerStyle 鼠标样式类型。 **系统能力**:SystemCapability.MultimodalInput.Input.Pointer | 名称 | 值 | 说明 |图示 | | -------------------------------- | ---- | ------ |------ | | DEFAULT | 0 | 默认 |![Default.png](./figures/Default.png)| | EAST | 1 | 向东箭头 |![East.png](./figures/East.png)| | WEST | 2 | 向西箭头 |![West.png](./figures/West.png)| | SOUTH | 3 | 向南箭头 |![South.png](./figures/South.png)| | NORTH | 4 | 向北箭头 |![North.png](./figures/North.png)| | WEST_EAST | 5 | 向西东箭头 |![West_East.png](./figures/West_East.png)| | NORTH_SOUTH | 6 | 向北南箭头 |![North_South.png](./figures/North_South.png)| | NORTH_EAST | 7 | 向东北箭头 |![North_East.png](./figures/North_East.png)| | NORTH_WEST | 8 | 向西北箭头 |![North_West.png](./figures/North_West.png)| | SOUTH_EAST | 9 | 向东南箭头 |![South_East.png](./figures/South_East.png)| | SOUTH_WEST | 10 | 向西南箭头 |![South_West.png](./figures/South_West.png)| | NORTH_EAST_SOUTH_WEST | 11 | 东北西南调整 |![North_East_South_West.png](./figures/North_East_South_West.png)| | NORTH_WEST_SOUTH_EAST | 12 | 西北东南调整 |![North_West_South_East.png](./figures/North_West_South_East.png)| | CROSS | 13 | 准确选择 |![Cross.png](./figures/Cross.png)| | CURSOR_COPY | 14 | 拷贝 |![Copy.png](./figures/Copy.png)| | CURSOR_FORBID | 15 | 不可用 |![Forbid.png](./figures/Forbid.png)| | COLOR_SUCKER | 16 | 滴管 |![Colorsucker.png](./figures/Colorsucker.png)| | HAND_GRABBING | 17 | 并拢的手 |![Hand_Grabbing.png](./figures/Hand_Grabbing.png)| | HAND_OPEN | 18 | 张开的手 |![Hand_Open.png](./figures/Hand_Open.png)| | HAND_POINTING | 19 | 手形指针 |![Hand_Poniting.png](./figures/Hand_Pointing.png)| | HELP | 20 | 帮助选择 |![Help.png](./figures/Help.png)| | MOVE | 21 | 移动 |![Move.png](./figures/Move.png)| | RESIZE_LEFT_RIGHT | 22 | 内部左右调整 |![Resize_Left_Right.png](./figures/Resize_Left_Right.png)| | RESIZE_UP_DOWN | 23 | 内部上下调整 |![Resize_Up_Down.png](./figures/Resize_Up_Down.png)| | SCREENSHOT_CHOOSE | 24 | 截图十字准星 |![Screenshot_Cross.png](./figures/Screenshot_Cross.png)| | SCREENSHOT_CURSOR | 25 | 截图 |![Screenshot_Cursor.png](./figures/Screenshot_Cursor.png)| | TEXT_CURSOR | 26 | 文本选择 |![Text_Cursor.png](./figures/Text_Cursor.png)| | ZOOM_IN | 27 | 放大 |![Zoom_In.png](./figures/Zoom_In.png)| | ZOOM_OUT | 28 | 缩小 |![Zoom_Out.png](./figures/Zoom_Out.png)| | MIDDLE_BTN_EAST | 29 | 向东滚动 |![MID_Btn_East.png](./figures/MID_Btn_East.png)| | MIDDLE_BTN_WEST | 30 | 向西滚动 |![MID_Btn_West.png](./figures/MID_Btn_West.png)| | MIDDLE_BTN_SOUTH | 31 | 向南滚动 | ![MID_Btn_South.png](./figures/MID_Btn_South.png) | | MIDDLE_BTN_NORTH | 32 | 向北滚动 |![MID_Btn_North.png](./figures/MID_Btn_North.png)| | MIDDLE_BTN_NORTH_SOUTH | 33 | 向南北滚动 |![MID_Btn_North_South.png](./figures/MID_Btn_North_South.png)| | MIDDLE_BTN_NORTH_EAST | 34 | 向东北滚动 |![MID_Btn_North_East.png](./figures/MID_Btn_North_East.png)| | MIDDLE_BTN_NORTH_WEST | 35 | 向西北滚动 |![MID_Btn_North_West.png](./figures/MID_Btn_North_West.png)| | MIDDLE_BTN_SOUTH_EAST | 36 | 向东南滚动 |![MID_Btn_South_East.png](./figures/MID_Btn_South_East.png)| | MIDDLE_BTN_SOUTH_WEST | 37 | 向西南滚动 |![MID_Btn_South_West.png](./figures/MID_Btn_South_West.png)| | MIDDLE_BTN_NORTH_SOUTH_WEST_EAST | 38 | 四向锥形移动 |![MID_Btn_North_South_West_East.png](./figures/MID_Btn_North_South_West_East.png)| | HORIZONTAL_TEXT_CURSOR10+ | 39 | 垂直文本选择 |![Horizontal_Text_Cursor.png](./figures/Horizontal_Text_Cursor.png)| | CURSOR_CROSS10+ | 40 | 十字光标 |![Cursor_Cross.png](./figures/Cursor_Cross.png)| | CURSOR_CIRCLE10+ | 41 | 圆形光标 |![Cursor_Circle.png](./figures/Cursor_Circle.png)| | LOADING10+ | 42 | 正在载入动画光标 |![Loading.png](./figures/Loading.png)
**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。| | RUNNING10+ | 43 | 后台运行中动画光标 |![Running.png](./figures/Running.png)
**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。| | MIDDLE_BTN_EAST_WEST18+ | 44 | 向东西滚动 |![MID_Btn_East_West.png](./figures/MID_Btn_East_West.png)| ## pointer.setCustomCursor11+ setCustomCursor(windowId: number, pixelMap: image.PixelMap, focusX?: number, focusY?: number): Promise<void> 设置自定义光标样式,使用Promise异步方式返回结果。 **系统能力**:SystemCapability.MultimodalInput.Input.Pointer **参数**: | 参数名 | 类型 | 必填 | 说明 | | ----- | ------ | ---- | ----------------------------------- | | windowId | number | 是 | 窗口id。 | | pixelMap | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | 是 | 自定义光标资源。 | | focusX | number | 否 | 自定义光标焦点x,取值范围:大于等于0,默认为0。 | | focusY | number | 否 | 自定义光标焦点y,取值范围:大于等于0,默认为0。 | **返回值**: | 参数 | 说明 | | ------------------- | ---------------- | | Promise<void> | 无返回结果的Promise对象。 | **错误码**: 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 | 错误码ID | 错误信息 | | ---- | --------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | **示例**: ```js import { image } from '@kit.ImageKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { window } from '@kit.ArkUI'; this.getUIContext()?.getHostContext()?.resourceManager.getMediaContent($r("app.media.app_icon")).then((svgFileData) => { const svgBuffer: ArrayBuffer = svgFileData.buffer.slice(0); let svgImagesource: image.ImageSource = image.createImageSource(svgBuffer); let svgDecodingOptions: image.DecodingOptions = {desiredSize: { width: 50, height:50 }}; 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.log(`setCustomCursor success`); }); } catch (error) { console.log(`setCustomCursor failed, error: ${JSON.stringify(error, [`code`, `message`])}`); } }); }); }); ``` ## CustomCursor15+ 自定义光标资源。 **系统能力**:SystemCapability.MultimodalInput.Input.Pointer | 名称 | 类型 | 可读 | 可写 | 说明 | | -------- | ------- | -------- | -------- | ------- | | pixelMap | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | 否 | 否 | 自定义光标。最小限制为资源图本身的最小限制。最大限制为256 x 256px。 | | focusX | number | 否 | 是 | 自定义光标焦点的水平坐标。该坐标受自定义光标大小的限制。最小值为0,最大值为资源图的宽度最大值,该参数缺省时默认为0。 | | focusY | number | 否 | 是 | 自定义光标焦点的垂直坐标。该坐标受自定义光标大小的限制。最小值为0,最大值为资源图的高度最大值,该参数缺省时默认为0。 | ## CursorConfig15+ 自定义光标配置。 **系统能力**:SystemCapability.MultimodalInput.Input.Pointer | 名称 | 类型 | 可读 | 可写 | 说明 | | -------- | ------- | -------- | -------- | ------- | | followSystem | boolean | 否 | 否 | 是否根据系统设置调整光标大小。false表示使用自定义光标样式大小,true表示根据系统设置调整光标大小,可调整范围为:[光标资源图大小,256×256]。 | ## pointer.setCustomCursor15+ setCustomCursor(windowId: number, cursor: CustomCursor, config: CursorConfig): Promise<void> 设置自定义光标样式,使用Promise异步回调。 应用窗口布局改变、热区切换、页面跳转、光标移出再回到窗口、光标在窗口不同区域移动,以上场景可能导致光标切换回系统样式,需要开发者重新设置光标样式。 **系统能力**:SystemCapability.MultimodalInput.Input.Pointer **参数**: | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | | windowId | number | 是 | 窗口id。 | | cursor | [CustomCursor](js-apis-pointer.md#customcursor15) | 是 | 自定义光标资源。 | | config | [CursorConfig](js-apis-pointer.md#cursorconfig15) | 是 | 自定义光标配置,用于配置是否根据系统设置调整光标大小。如果CursorConfig中followSystem设置为true,则光标大小的可调整范围为:[光标资源图大小,256×256]。 | **返回值**: | 参数 | 说明 | | ------------------- | ---------------- | | Promise<void> | 无返回结果的Promise对象。 | **错误码**: 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[输入设备错误码](./errorcode-inputdevice.md)。 | 错误码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. | **示例**: ```js import { image } from '@kit.ImageKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { window } from '@kit.ArkUI'; this.getUIContext()?.getHostContext()?.resourceManager.getMediaContent($r("app.media.app_icon")).then((svgFileData) => { const svgBuffer: ArrayBuffer = svgFileData.buffer.slice(0); let svgImagesource: image.ImageSource = image.createImageSource(svgBuffer); let svgDecodingOptions: image.DecodingOptions = {desiredSize: { width: 50, height:50 }}; 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.log(`setCustomCursor success`); }); } catch (error) { console.log(`setCustomCursor failed, error: ${JSON.stringify(error, [`code`, `message`])}`); } }); }); }); ``` ## pointer.setCustomCursorSync11+ setCustomCursorSync(windowId: number, pixelMap: image.PixelMap, focusX?: number, focusY?: number): void 设置自定义光标样式,使用同步方式进行设置。 **系统能力**:SystemCapability.MultimodalInput.Input.Pointer **参数**: | 参数名 | 类型 | 必填 | 说明 | | ----- | ------ | ---- | ----------------------------------- | | windowId | number | 是 | 窗口id。 | | pixelMap | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | 是 | 自定义光标资源。 | | focusX | number | 否 | 自定义光标焦点x,取值范围:大于等于0,默认为0。 | | focusY | number | 否 | 自定义光标焦点y,取值范围:大于等于0,默认为0。 | **错误码**: 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 | 错误码ID | 错误信息 | | ---- | --------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | **示例**: ```js import { image } from '@kit.ImageKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { window } from '@kit.ArkUI'; const svgFileData = this.getUIContext()?.getHostContext()?.resourceManager.getMediaContent($r("app.media.app_icon")).then((svgFileData) => { const svgBuffer: ArrayBuffer = svgFileData.buffer.slice(0); let svgImagesource: image.ImageSource = image.createImageSource(svgBuffer); let svgDecodingOptions: image.DecodingOptions = {desiredSize: { width: 50, height:50 }}; 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.log(`setCustomCursorSync success`); } catch (error) { console.log(`setCustomCursorSync failed, error: ${JSON.stringify(error, [`code`, `message`])}`); } }); }); }); ```