1e41f4b71Sopenharmony_ci# @ohos.multimodalInput.pointer (鼠标指针) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci鼠标指针管理模块,用于查询和设置鼠标指针相关属性。 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **说明**: 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci## 导入模块 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci```js 12e41f4b71Sopenharmony_ciimport { pointer } from '@kit.InputKit'; 13e41f4b71Sopenharmony_ci``` 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci## pointer.setPointerVisible 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_cisetPointerVisible(visible: boolean, callback: AsyncCallback<void>): void 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci设置鼠标指针显示或者隐藏,使用AsyncCallback异步方式返回结果。 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.MultimodalInput.Input.Pointer 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci**参数**: 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 26e41f4b71Sopenharmony_ci| -------- | ------------------------- | ---- | ---------------------------------------- | 27e41f4b71Sopenharmony_ci| visible | boolean | 是 | 鼠标指针是否显示。true表示显示,false表示不显示 | 28e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | 是 | 回调函数。 | 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci**错误码**: 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 35e41f4b71Sopenharmony_ci| ---- | --------------------- | 36e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci**示例**: 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci```js 41e41f4b71Sopenharmony_citry { 42e41f4b71Sopenharmony_ci pointer.setPointerVisible(true, (error: Error) => { 43e41f4b71Sopenharmony_ci if (error) { 44e41f4b71Sopenharmony_ci console.log(`Set pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 45e41f4b71Sopenharmony_ci return; 46e41f4b71Sopenharmony_ci } 47e41f4b71Sopenharmony_ci console.log(`Set pointer visible success`); 48e41f4b71Sopenharmony_ci }); 49e41f4b71Sopenharmony_ci} catch (error) { 50e41f4b71Sopenharmony_ci console.log(`Set pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 51e41f4b71Sopenharmony_ci} 52e41f4b71Sopenharmony_ci``` 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ci## pointer.setPointerVisible 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_cisetPointerVisible(visible: boolean): Promise<void> 57e41f4b71Sopenharmony_ci 58e41f4b71Sopenharmony_ci设置鼠标指针显示或者隐藏,使用Promise异步方式返回结果。 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.MultimodalInput.Input.Pointer 61e41f4b71Sopenharmony_ci 62e41f4b71Sopenharmony_ci**参数**: 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 65e41f4b71Sopenharmony_ci| ------- | ------- | ---- | ---------------------------------------- | 66e41f4b71Sopenharmony_ci| visible | boolean | 是 | 鼠标指针是否显示。true表示显示,false表示不显示。 | 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ci**返回值**: 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ci| 参数 | 说明 | 71e41f4b71Sopenharmony_ci| ------------------- | ------------------- | 72e41f4b71Sopenharmony_ci| Promise<void> | Promise对象。 | 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ci**错误码**: 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。。 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 79e41f4b71Sopenharmony_ci| ---- | --------------------- | 80e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_ci**示例**: 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ci```js 85e41f4b71Sopenharmony_citry { 86e41f4b71Sopenharmony_ci pointer.setPointerVisible(false).then(() => { 87e41f4b71Sopenharmony_ci console.log(`Set pointer visible success`); 88e41f4b71Sopenharmony_ci }); 89e41f4b71Sopenharmony_ci} catch (error) { 90e41f4b71Sopenharmony_ci console.log(`Set pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 91e41f4b71Sopenharmony_ci} 92e41f4b71Sopenharmony_ci``` 93e41f4b71Sopenharmony_ci 94e41f4b71Sopenharmony_ci## pointer.setPointerVisibleSync<sup>10+</sup> 95e41f4b71Sopenharmony_ci 96e41f4b71Sopenharmony_cisetPointerVisibleSync(visible: boolean): void 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ci使用同步方式设置鼠标指针显示或者隐藏。 99e41f4b71Sopenharmony_ci 100e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.MultimodalInput.Input.Pointer 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ci**参数**: 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 105e41f4b71Sopenharmony_ci| ------- | ------- | ---- | ---------------------------------------- | 106e41f4b71Sopenharmony_ci| visible | boolean | 是 | 鼠标指针是否显示。true表示显示,false表示不显示。 | 107e41f4b71Sopenharmony_ci 108e41f4b71Sopenharmony_ci**错误码**: 109e41f4b71Sopenharmony_ci 110e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 111e41f4b71Sopenharmony_ci 112e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 113e41f4b71Sopenharmony_ci| ---- | --------------------- | 114e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 115e41f4b71Sopenharmony_ci 116e41f4b71Sopenharmony_ci**示例**: 117e41f4b71Sopenharmony_ci 118e41f4b71Sopenharmony_ci```js 119e41f4b71Sopenharmony_citry { 120e41f4b71Sopenharmony_ci pointer.setPointerVisibleSync(false); 121e41f4b71Sopenharmony_ci console.log(`Set pointer visible success`); 122e41f4b71Sopenharmony_ci} catch (error) { 123e41f4b71Sopenharmony_ci console.log(`Set pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 124e41f4b71Sopenharmony_ci} 125e41f4b71Sopenharmony_ci``` 126e41f4b71Sopenharmony_ci 127e41f4b71Sopenharmony_ci## pointer.isPointerVisible 128e41f4b71Sopenharmony_ci 129e41f4b71Sopenharmony_ciisPointerVisible(callback: AsyncCallback<boolean>): void 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_ci获取鼠标指针显示或隐藏状态,使用AsyncCallback异步方式返回结果。 132e41f4b71Sopenharmony_ci 133e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.MultimodalInput.Input.Pointer 134e41f4b71Sopenharmony_ci 135e41f4b71Sopenharmony_ci**参数**: 136e41f4b71Sopenharmony_ci 137e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 138e41f4b71Sopenharmony_ci| -------- | ---------------------------- | ---- | -------------- | 139e41f4b71Sopenharmony_ci| callback | AsyncCallback<boolean> | 是 | 回调函数,异步返回鼠标指针状态,true为显示,false为隐藏。 | 140e41f4b71Sopenharmony_ci 141e41f4b71Sopenharmony_ci**错误码**: 142e41f4b71Sopenharmony_ci 143e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 144e41f4b71Sopenharmony_ci 145e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 146e41f4b71Sopenharmony_ci| ---- | --------------------- | 147e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 148e41f4b71Sopenharmony_ci 149e41f4b71Sopenharmony_ci**示例**: 150e41f4b71Sopenharmony_ci 151e41f4b71Sopenharmony_ci```js 152e41f4b71Sopenharmony_citry { 153e41f4b71Sopenharmony_ci pointer.isPointerVisible((error: Error, visible: boolean) => { 154e41f4b71Sopenharmony_ci if (error) { 155e41f4b71Sopenharmony_ci console.log(`Get pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 156e41f4b71Sopenharmony_ci return; 157e41f4b71Sopenharmony_ci } 158e41f4b71Sopenharmony_ci console.log(`Get pointer visible success, visible: ${JSON.stringify(visible)}`); 159e41f4b71Sopenharmony_ci }); 160e41f4b71Sopenharmony_ci} catch (error) { 161e41f4b71Sopenharmony_ci console.log(`Get pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 162e41f4b71Sopenharmony_ci} 163e41f4b71Sopenharmony_ci``` 164e41f4b71Sopenharmony_ci 165e41f4b71Sopenharmony_ci## pointer.isPointerVisible 166e41f4b71Sopenharmony_ci 167e41f4b71Sopenharmony_ciisPointerVisible(): Promise<boolean> 168e41f4b71Sopenharmony_ci 169e41f4b71Sopenharmony_ci获取鼠标指针显示或隐藏状态,使用Promise异步方式返回结果。 170e41f4b71Sopenharmony_ci 171e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.MultimodalInput.Input.Pointer 172e41f4b71Sopenharmony_ci 173e41f4b71Sopenharmony_ci**返回值**: 174e41f4b71Sopenharmony_ci 175e41f4b71Sopenharmony_ci| 参数 | 说明 | 176e41f4b71Sopenharmony_ci| ---------------------- | ------------------- | 177e41f4b71Sopenharmony_ci| Promise<boolean> | Promise对象,异步返回鼠标指针显示或隐藏状态。 | 178e41f4b71Sopenharmony_ci 179e41f4b71Sopenharmony_ci**示例**: 180e41f4b71Sopenharmony_ci 181e41f4b71Sopenharmony_ci```js 182e41f4b71Sopenharmony_citry { 183e41f4b71Sopenharmony_ci pointer.isPointerVisible().then((visible: boolean) => { 184e41f4b71Sopenharmony_ci console.log(`Get pointer visible success, visible: ${JSON.stringify(visible)}`); 185e41f4b71Sopenharmony_ci }); 186e41f4b71Sopenharmony_ci} catch (error) { 187e41f4b71Sopenharmony_ci console.log(`Get pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 188e41f4b71Sopenharmony_ci} 189e41f4b71Sopenharmony_ci``` 190e41f4b71Sopenharmony_ci 191e41f4b71Sopenharmony_ci## pointer.isPointerVisibleSync<sup>10+</sup> 192e41f4b71Sopenharmony_ci 193e41f4b71Sopenharmony_ciisPointerVisibleSync(): boolean 194e41f4b71Sopenharmony_ci 195e41f4b71Sopenharmony_ci使用同步方式获取鼠标指针显示或者隐藏。 196e41f4b71Sopenharmony_ci 197e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.MultimodalInput.Input.Pointer 198e41f4b71Sopenharmony_ci 199e41f4b71Sopenharmony_ci**返回值**: 200e41f4b71Sopenharmony_ci 201e41f4b71Sopenharmony_ci| 参数 | 说明 | 202e41f4b71Sopenharmony_ci| ---------------------- | ------------------- | 203e41f4b71Sopenharmony_ci| boolean | 返回鼠标指针显示或隐藏状态。true代表显示状态,false代表隐藏状态。 | 204e41f4b71Sopenharmony_ci 205e41f4b71Sopenharmony_ci**示例**: 206e41f4b71Sopenharmony_ci 207e41f4b71Sopenharmony_ci```js 208e41f4b71Sopenharmony_citry { 209e41f4b71Sopenharmony_ci let visible: boolean = pointer.isPointerVisibleSync(); 210e41f4b71Sopenharmony_ci console.log(`Get pointer visible success, visible: ${JSON.stringify(visible)}`); 211e41f4b71Sopenharmony_ci} catch (error) { 212e41f4b71Sopenharmony_ci console.log(`Get pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 213e41f4b71Sopenharmony_ci} 214e41f4b71Sopenharmony_ci``` 215e41f4b71Sopenharmony_ci 216e41f4b71Sopenharmony_ci## pointer.getPointerStyle 217e41f4b71Sopenharmony_ci 218e41f4b71Sopenharmony_cigetPointerStyle(windowId: number, callback: AsyncCallback<PointerStyle>): void 219e41f4b71Sopenharmony_ci 220e41f4b71Sopenharmony_ci获取鼠标样式类型,使用AsyncCallback异步方式返回结果。 221e41f4b71Sopenharmony_ci 222e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.MultimodalInput.Input.Pointer 223e41f4b71Sopenharmony_ci 224e41f4b71Sopenharmony_ci**参数**: 225e41f4b71Sopenharmony_ci 226e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 227e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | -------------- | 228e41f4b71Sopenharmony_ci| windowId | number | 是 | 窗口id。 | 229e41f4b71Sopenharmony_ci| callback | AsyncCallback<[PointerStyle](#pointerstyle)> | 是 | 回调函数,异步返回鼠标样式类型。 | 230e41f4b71Sopenharmony_ci 231e41f4b71Sopenharmony_ci**错误码**: 232e41f4b71Sopenharmony_ci 233e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 234e41f4b71Sopenharmony_ci 235e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 236e41f4b71Sopenharmony_ci| ---- | --------------------- | 237e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 238e41f4b71Sopenharmony_ci 239e41f4b71Sopenharmony_ci**示例**: 240e41f4b71Sopenharmony_ci 241e41f4b71Sopenharmony_ci```js 242e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 243e41f4b71Sopenharmony_ciimport { window } from '@kit.ArkUI'; 244e41f4b71Sopenharmony_ci 245e41f4b71Sopenharmony_cilet context = getContext(this); 246e41f4b71Sopenharmony_ciwindow.getLastWindow(context, (error: BusinessError, win: window.Window) => { 247e41f4b71Sopenharmony_ci if (error.code) { 248e41f4b71Sopenharmony_ci console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(error)); 249e41f4b71Sopenharmony_ci return; 250e41f4b71Sopenharmony_ci } 251e41f4b71Sopenharmony_ci let windowId = win.getWindowProperties().id; 252e41f4b71Sopenharmony_ci if (windowId < 0) { 253e41f4b71Sopenharmony_ci console.log(`Invalid windowId`); 254e41f4b71Sopenharmony_ci return; 255e41f4b71Sopenharmony_ci } 256e41f4b71Sopenharmony_ci try { 257e41f4b71Sopenharmony_ci pointer.getPointerStyle(windowId, (error: Error, style: pointer.PointerStyle) => { 258e41f4b71Sopenharmony_ci console.log(`Get pointer style success, style: ${JSON.stringify(style)}`); 259e41f4b71Sopenharmony_ci }); 260e41f4b71Sopenharmony_ci } catch (error) { 261e41f4b71Sopenharmony_ci console.log(`Get pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 262e41f4b71Sopenharmony_ci } 263e41f4b71Sopenharmony_ci}); 264e41f4b71Sopenharmony_ci``` 265e41f4b71Sopenharmony_ci 266e41f4b71Sopenharmony_ci## pointer.getPointerStyle 267e41f4b71Sopenharmony_ci 268e41f4b71Sopenharmony_cigetPointerStyle(windowId: number): Promise<PointerStyle> 269e41f4b71Sopenharmony_ci 270e41f4b71Sopenharmony_ci获取鼠标样式类型,使用Promise异步方式返回结果。 271e41f4b71Sopenharmony_ci 272e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.MultimodalInput.Input.Pointer 273e41f4b71Sopenharmony_ci 274e41f4b71Sopenharmony_ci**参数**: 275e41f4b71Sopenharmony_ci 276e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 277e41f4b71Sopenharmony_ci| -------- | ------ | ---- | -------- | 278e41f4b71Sopenharmony_ci| windowId | number | 是 | 窗口id。 | 279e41f4b71Sopenharmony_ci 280e41f4b71Sopenharmony_ci**返回值**: 281e41f4b71Sopenharmony_ci 282e41f4b71Sopenharmony_ci| 参数 | 说明 | 283e41f4b71Sopenharmony_ci| ---------------------------------------- | ------------------- | 284e41f4b71Sopenharmony_ci| Promise<[PointerStyle](#pointerstyle)> | Promise实例,异步返回鼠标样式类型。 | 285e41f4b71Sopenharmony_ci 286e41f4b71Sopenharmony_ci**错误码**: 287e41f4b71Sopenharmony_ci 288e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 289e41f4b71Sopenharmony_ci 290e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 291e41f4b71Sopenharmony_ci| ---- | --------------------- | 292e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 293e41f4b71Sopenharmony_ci 294e41f4b71Sopenharmony_ci**示例**: 295e41f4b71Sopenharmony_ci 296e41f4b71Sopenharmony_ci```js 297e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 298e41f4b71Sopenharmony_ciimport { window } from '@kit.ArkUI'; 299e41f4b71Sopenharmony_ci 300e41f4b71Sopenharmony_cilet context = getContext(this); 301e41f4b71Sopenharmony_ciwindow.getLastWindow(context, (error: BusinessError, win: window.Window) => { 302e41f4b71Sopenharmony_ci if (error.code) { 303e41f4b71Sopenharmony_ci console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(error)); 304e41f4b71Sopenharmony_ci return; 305e41f4b71Sopenharmony_ci } 306e41f4b71Sopenharmony_ci let windowId = win.getWindowProperties().id; 307e41f4b71Sopenharmony_ci if (windowId < 0) { 308e41f4b71Sopenharmony_ci console.log(`Invalid windowId`); 309e41f4b71Sopenharmony_ci return; 310e41f4b71Sopenharmony_ci } 311e41f4b71Sopenharmony_ci try { 312e41f4b71Sopenharmony_ci pointer.getPointerStyle(windowId).then((style: pointer.PointerStyle) => { 313e41f4b71Sopenharmony_ci console.log(`Get pointer style success, style: ${JSON.stringify(style)}`); 314e41f4b71Sopenharmony_ci }); 315e41f4b71Sopenharmony_ci } catch (error) { 316e41f4b71Sopenharmony_ci console.log(`Get pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 317e41f4b71Sopenharmony_ci } 318e41f4b71Sopenharmony_ci}); 319e41f4b71Sopenharmony_ci``` 320e41f4b71Sopenharmony_ci 321e41f4b71Sopenharmony_ci## pointer.getPointerStyleSync<sup>10+</sup> 322e41f4b71Sopenharmony_ci 323e41f4b71Sopenharmony_cigetPointerStyleSync(windowId: number): PointerStyle 324e41f4b71Sopenharmony_ci 325e41f4b71Sopenharmony_ci使用同步方式获取鼠标样式类型。 326e41f4b71Sopenharmony_ci 327e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.MultimodalInput.Input.Pointer 328e41f4b71Sopenharmony_ci 329e41f4b71Sopenharmony_ci**参数**: 330e41f4b71Sopenharmony_ci 331e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 332e41f4b71Sopenharmony_ci| -------- | ------ | ---- | -------- | 333e41f4b71Sopenharmony_ci| windowId | number | 是 | 窗口id。<br>默认值为-1,表示获取全局的鼠标样式。 | 334e41f4b71Sopenharmony_ci 335e41f4b71Sopenharmony_ci**返回值**: 336e41f4b71Sopenharmony_ci 337e41f4b71Sopenharmony_ci| 参数 | 说明 | 338e41f4b71Sopenharmony_ci| ---------------------------------------- | ------------------- | 339e41f4b71Sopenharmony_ci| [PointerStyle](#pointerstyle) | 返回鼠标样式类型。 | 340e41f4b71Sopenharmony_ci 341e41f4b71Sopenharmony_ci**错误码**: 342e41f4b71Sopenharmony_ci 343e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 344e41f4b71Sopenharmony_ci 345e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 346e41f4b71Sopenharmony_ci| ---- | --------------------- | 347e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 348e41f4b71Sopenharmony_ci 349e41f4b71Sopenharmony_ci**示例**: 350e41f4b71Sopenharmony_ci 351e41f4b71Sopenharmony_ci```js 352e41f4b71Sopenharmony_ciimport { pointer } from '@kit.InputKit'; 353e41f4b71Sopenharmony_ci 354e41f4b71Sopenharmony_cilet windowId = -1; 355e41f4b71Sopenharmony_citry { 356e41f4b71Sopenharmony_ci let style: pointer.PointerStyle = pointer.getPointerStyleSync(windowId); 357e41f4b71Sopenharmony_ci console.log(`Get pointer style success, style: ${JSON.stringify(style)}`); 358e41f4b71Sopenharmony_ci} catch (error) { 359e41f4b71Sopenharmony_ci console.log(`Get pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 360e41f4b71Sopenharmony_ci} 361e41f4b71Sopenharmony_ci``` 362e41f4b71Sopenharmony_ci 363e41f4b71Sopenharmony_ci## pointer.setPointerStyle 364e41f4b71Sopenharmony_ci 365e41f4b71Sopenharmony_cisetPointerStyle(windowId: number, pointerStyle: PointerStyle, callback: AsyncCallback<void>): void 366e41f4b71Sopenharmony_ci 367e41f4b71Sopenharmony_ci设置鼠标样式类型,使用AsyncCallback异步方式返回结果。 368e41f4b71Sopenharmony_ci 369e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.MultimodalInput.Input.Pointer 370e41f4b71Sopenharmony_ci 371e41f4b71Sopenharmony_ci**参数**: 372e41f4b71Sopenharmony_ci 373e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 374e41f4b71Sopenharmony_ci| ------------ | ------------------------------ | ---- | ----------------------------------- | 375e41f4b71Sopenharmony_ci| windowId | number | 是 | 窗口id。 | 376e41f4b71Sopenharmony_ci| pointerStyle | [PointerStyle](#pointerstyle) | 是 | 鼠标样式。 | 377e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | 是 | 回调函数。 | 378e41f4b71Sopenharmony_ci 379e41f4b71Sopenharmony_ci**错误码**: 380e41f4b71Sopenharmony_ci 381e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 382e41f4b71Sopenharmony_ci 383e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 384e41f4b71Sopenharmony_ci| ---- | --------------------- | 385e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 386e41f4b71Sopenharmony_ci 387e41f4b71Sopenharmony_ci**示例**: 388e41f4b71Sopenharmony_ci 389e41f4b71Sopenharmony_ci```js 390e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 391e41f4b71Sopenharmony_ciimport { window } from '@kit.ArkUI'; 392e41f4b71Sopenharmony_ci 393e41f4b71Sopenharmony_ciwindow.getLastWindow(getContext(), (error: BusinessError, win: window.Window) => { 394e41f4b71Sopenharmony_ci if (error.code) { 395e41f4b71Sopenharmony_ci console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(error)); 396e41f4b71Sopenharmony_ci return; 397e41f4b71Sopenharmony_ci } 398e41f4b71Sopenharmony_ci let windowId = win.getWindowProperties().id; 399e41f4b71Sopenharmony_ci if (windowId < 0) { 400e41f4b71Sopenharmony_ci console.log(`Invalid windowId`); 401e41f4b71Sopenharmony_ci return; 402e41f4b71Sopenharmony_ci } 403e41f4b71Sopenharmony_ci try { 404e41f4b71Sopenharmony_ci pointer.setPointerStyle(windowId, pointer.PointerStyle.CROSS, error => { 405e41f4b71Sopenharmony_ci console.log(`Set pointer style success`); 406e41f4b71Sopenharmony_ci }); 407e41f4b71Sopenharmony_ci } catch (error) { 408e41f4b71Sopenharmony_ci console.log(`Set pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 409e41f4b71Sopenharmony_ci } 410e41f4b71Sopenharmony_ci}); 411e41f4b71Sopenharmony_ci``` 412e41f4b71Sopenharmony_ci## pointer.setPointerStyle 413e41f4b71Sopenharmony_ci 414e41f4b71Sopenharmony_cisetPointerStyle(windowId: number, pointerStyle: PointerStyle): Promise<void> 415e41f4b71Sopenharmony_ci 416e41f4b71Sopenharmony_ci设置鼠标样式类型,使用Promise异步方式返回结果。 417e41f4b71Sopenharmony_ci 418e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.MultimodalInput.Input.Pointer 419e41f4b71Sopenharmony_ci 420e41f4b71Sopenharmony_ci**参数**: 421e41f4b71Sopenharmony_ci 422e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 423e41f4b71Sopenharmony_ci| ------------------- | ------------------------------ | ---- | ---------------- | 424e41f4b71Sopenharmony_ci| windowId | number | 是 | 窗口id。 | 425e41f4b71Sopenharmony_ci| pointerStyle | [PointerStyle](#pointerstyle) | 是 | 鼠标样式。 | 426e41f4b71Sopenharmony_ci 427e41f4b71Sopenharmony_ci**返回值**: 428e41f4b71Sopenharmony_ci 429e41f4b71Sopenharmony_ci| 参数 | 说明 | 430e41f4b71Sopenharmony_ci| ------------------- | ------------------- | 431e41f4b71Sopenharmony_ci| Promise<void> | Promise对象。 | 432e41f4b71Sopenharmony_ci 433e41f4b71Sopenharmony_ci**错误码**: 434e41f4b71Sopenharmony_ci 435e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 436e41f4b71Sopenharmony_ci 437e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 438e41f4b71Sopenharmony_ci| ---- | --------------------- | 439e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 440e41f4b71Sopenharmony_ci 441e41f4b71Sopenharmony_ci**示例**: 442e41f4b71Sopenharmony_ci 443e41f4b71Sopenharmony_ci```js 444e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 445e41f4b71Sopenharmony_ciimport { window } from '@kit.ArkUI'; 446e41f4b71Sopenharmony_ci 447e41f4b71Sopenharmony_ciwindow.getLastWindow(getContext(), (error: BusinessError, win: window.Window) => { 448e41f4b71Sopenharmony_ci if (error.code) { 449e41f4b71Sopenharmony_ci console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(error)); 450e41f4b71Sopenharmony_ci return; 451e41f4b71Sopenharmony_ci } 452e41f4b71Sopenharmony_ci let windowId = win.getWindowProperties().id; 453e41f4b71Sopenharmony_ci if (windowId < 0) { 454e41f4b71Sopenharmony_ci console.log(`Invalid windowId`); 455e41f4b71Sopenharmony_ci return; 456e41f4b71Sopenharmony_ci } 457e41f4b71Sopenharmony_ci try { 458e41f4b71Sopenharmony_ci pointer.setPointerStyle(windowId, pointer.PointerStyle.CROSS).then(() => { 459e41f4b71Sopenharmony_ci console.log(`Set pointer style success`); 460e41f4b71Sopenharmony_ci }); 461e41f4b71Sopenharmony_ci } catch (error) { 462e41f4b71Sopenharmony_ci console.log(`Set pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 463e41f4b71Sopenharmony_ci } 464e41f4b71Sopenharmony_ci}); 465e41f4b71Sopenharmony_ci``` 466e41f4b71Sopenharmony_ci 467e41f4b71Sopenharmony_ci## pointer.setPointerStyleSync<sup>10+</sup> 468e41f4b71Sopenharmony_ci 469e41f4b71Sopenharmony_cisetPointerStyleSync(windowId: number, pointerStyle: PointerStyle): void 470e41f4b71Sopenharmony_ci 471e41f4b71Sopenharmony_ci使用同步方式设置鼠标样式类型。 472e41f4b71Sopenharmony_ci 473e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.MultimodalInput.Input.Pointer 474e41f4b71Sopenharmony_ci 475e41f4b71Sopenharmony_ci**参数**: 476e41f4b71Sopenharmony_ci 477e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 478e41f4b71Sopenharmony_ci| ------------------- | ------------------------------ | ---- | ---------------- | 479e41f4b71Sopenharmony_ci| windowId | number | 是 | 窗口id。 | 480e41f4b71Sopenharmony_ci| pointerStyle | [PointerStyle](#pointerstyle) | 是 | 鼠标样式。 | 481e41f4b71Sopenharmony_ci 482e41f4b71Sopenharmony_ci**错误码**: 483e41f4b71Sopenharmony_ci 484e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 485e41f4b71Sopenharmony_ci 486e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 487e41f4b71Sopenharmony_ci| ---- | --------------------- | 488e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 489e41f4b71Sopenharmony_ci 490e41f4b71Sopenharmony_ci**示例**: 491e41f4b71Sopenharmony_ci```js 492e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 493e41f4b71Sopenharmony_ciimport { window } from '@kit.ArkUI'; 494e41f4b71Sopenharmony_ci 495e41f4b71Sopenharmony_ciwindow.getLastWindow(getContext(), (error: BusinessError, win: window.Window) => { 496e41f4b71Sopenharmony_ci if (error.code) { 497e41f4b71Sopenharmony_ci console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(error)); 498e41f4b71Sopenharmony_ci return; 499e41f4b71Sopenharmony_ci } 500e41f4b71Sopenharmony_ci let windowId = win.getWindowProperties().id; 501e41f4b71Sopenharmony_ci if (windowId < 0) { 502e41f4b71Sopenharmony_ci console.log(`Invalid windowId`); 503e41f4b71Sopenharmony_ci return; 504e41f4b71Sopenharmony_ci } 505e41f4b71Sopenharmony_ci try { 506e41f4b71Sopenharmony_ci pointer.setPointerStyleSync(windowId, pointer.PointerStyle.CROSS); 507e41f4b71Sopenharmony_ci console.log(`Set pointer style success`); 508e41f4b71Sopenharmony_ci } catch (error) { 509e41f4b71Sopenharmony_ci console.log(`getPointerSize failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 510e41f4b71Sopenharmony_ci } 511e41f4b71Sopenharmony_ci}); 512e41f4b71Sopenharmony_ci``` 513e41f4b71Sopenharmony_ci 514e41f4b71Sopenharmony_ci## PrimaryButton<sup>10+</sup> 515e41f4b71Sopenharmony_ci 516e41f4b71Sopenharmony_ci鼠标主键类型。 517e41f4b71Sopenharmony_ci 518e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.MultimodalInput.Input.Pointer 519e41f4b71Sopenharmony_ci 520e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 | 521e41f4b71Sopenharmony_ci| -------------------------------- | ---- | ------ | 522e41f4b71Sopenharmony_ci| LEFT | 0 | 鼠标左键 | 523e41f4b71Sopenharmony_ci| RIGHT | 1 | 鼠标右键 | 524e41f4b71Sopenharmony_ci 525e41f4b71Sopenharmony_ci## RightClickType<sup>10+</sup> 526e41f4b71Sopenharmony_ci 527e41f4b71Sopenharmony_ci右键菜单触发方式。 528e41f4b71Sopenharmony_ci 529e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.MultimodalInput.Input.Pointer 530e41f4b71Sopenharmony_ci 531e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 | 532e41f4b71Sopenharmony_ci| -------------------------------- | ---- | ------ | 533e41f4b71Sopenharmony_ci| TOUCHPAD_RIGHT_BUTTON | 1 |触控板右键区域。 | 534e41f4b71Sopenharmony_ci| TOUCHPAD_LEFT_BUTTON | 2 |触控板左键区域。 | 535e41f4b71Sopenharmony_ci| TOUCHPAD_TWO_FINGER_TAP | 3 |双指轻击或按压触控板。| 536e41f4b71Sopenharmony_ci 537e41f4b71Sopenharmony_ci## PointerStyle 538e41f4b71Sopenharmony_ci 539e41f4b71Sopenharmony_ci鼠标样式类型。 540e41f4b71Sopenharmony_ci 541e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.MultimodalInput.Input.Pointer 542e41f4b71Sopenharmony_ci 543e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 |图示 | 544e41f4b71Sopenharmony_ci| -------------------------------- | ---- | ------ |------ | 545e41f4b71Sopenharmony_ci| DEFAULT | 0 | 默认 || 546e41f4b71Sopenharmony_ci| EAST | 1 | 向东箭头 || 547e41f4b71Sopenharmony_ci| WEST | 2 | 向西箭头 || 548e41f4b71Sopenharmony_ci| SOUTH | 3 | 向南箭头 || 549e41f4b71Sopenharmony_ci| NORTH | 4 | 向北箭头 || 550e41f4b71Sopenharmony_ci| WEST_EAST | 5 | 向西东箭头 || 551e41f4b71Sopenharmony_ci| NORTH_SOUTH | 6 | 向北南箭头 || 552e41f4b71Sopenharmony_ci| NORTH_EAST | 7 | 向东北箭头 || 553e41f4b71Sopenharmony_ci| NORTH_WEST | 8 | 向西北箭头 || 554e41f4b71Sopenharmony_ci| SOUTH_EAST | 9 | 向东南箭头 || 555e41f4b71Sopenharmony_ci| SOUTH_WEST | 10 | 向西南箭头 || 556e41f4b71Sopenharmony_ci| NORTH_EAST_SOUTH_WEST | 11 | 东北西南调整 || 557e41f4b71Sopenharmony_ci| NORTH_WEST_SOUTH_EAST | 12 | 西北东南调整 || 558e41f4b71Sopenharmony_ci| CROSS | 13 | 准确选择 || 559e41f4b71Sopenharmony_ci| CURSOR_COPY | 14 | 拷贝 || 560e41f4b71Sopenharmony_ci| CURSOR_FORBID | 15 | 不可用 || 561e41f4b71Sopenharmony_ci| COLOR_SUCKER | 16 | 滴管 || 562e41f4b71Sopenharmony_ci| HAND_GRABBING | 17 | 并拢的手 || 563e41f4b71Sopenharmony_ci| HAND_OPEN | 18 | 张开的手 || 564e41f4b71Sopenharmony_ci| HAND_POINTING | 19 | 手形指针 || 565e41f4b71Sopenharmony_ci| HELP | 20 | 帮助选择 || 566e41f4b71Sopenharmony_ci| MOVE | 21 | 移动 || 567e41f4b71Sopenharmony_ci| RESIZE_LEFT_RIGHT | 22 | 内部左右调整 || 568e41f4b71Sopenharmony_ci| RESIZE_UP_DOWN | 23 | 内部上下调整 || 569e41f4b71Sopenharmony_ci| SCREENSHOT_CHOOSE | 24 | 截图十字准星 || 570e41f4b71Sopenharmony_ci| SCREENSHOT_CURSOR | 25 | 截图 || 571e41f4b71Sopenharmony_ci| TEXT_CURSOR | 26 | 文本选择 || 572e41f4b71Sopenharmony_ci| ZOOM_IN | 27 | 放大 || 573e41f4b71Sopenharmony_ci| ZOOM_OUT | 28 | 缩小 || 574e41f4b71Sopenharmony_ci| MIDDLE_BTN_EAST | 29 | 向东滚动 || 575e41f4b71Sopenharmony_ci| MIDDLE_BTN_WEST | 30 | 向西滚动 || 576e41f4b71Sopenharmony_ci| MIDDLE_BTN_SOUTH | 31 | 向南滚动 |  | 577e41f4b71Sopenharmony_ci| MIDDLE_BTN_NORTH | 32 | 向北滚动 || 578e41f4b71Sopenharmony_ci| MIDDLE_BTN_NORTH_SOUTH | 33 | 向北南滚动 || 579e41f4b71Sopenharmony_ci| MIDDLE_BTN_NORTH_EAST | 34 | 向东北滚动 || 580e41f4b71Sopenharmony_ci| MIDDLE_BTN_NORTH_WEST | 35 | 向西北滚动 || 581e41f4b71Sopenharmony_ci| MIDDLE_BTN_SOUTH_EAST | 36 | 向东南滚动 || 582e41f4b71Sopenharmony_ci| MIDDLE_BTN_SOUTH_WEST | 37 | 向西南滚动 || 583e41f4b71Sopenharmony_ci| MIDDLE_BTN_NORTH_SOUTH_WEST_EAST | 38 | 四向锥形移动 || 584e41f4b71Sopenharmony_ci| HORIZONTAL_TEXT_CURSOR<sup>10+</sup> | 39 | 垂直文本选择 || 585e41f4b71Sopenharmony_ci| CURSOR_CROSS<sup>10+</sup> | 40 | 十字光标 || 586e41f4b71Sopenharmony_ci| CURSOR_CIRCLE<sup>10+</sup> | 41 | 圆形光标 || 587e41f4b71Sopenharmony_ci| LOADING<sup>10+</sup> | 42 | 正在载入动画光标 |<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。| 588e41f4b71Sopenharmony_ci| RUNNING<sup>10+</sup> | 43 | 后台运行中动画光标 |<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。| 589e41f4b71Sopenharmony_ci 590e41f4b71Sopenharmony_ci## pointer.setCustomCursor<sup>11+</sup> 591e41f4b71Sopenharmony_ci 592e41f4b71Sopenharmony_cisetCustomCursor(windowId: number, pixelMap: image.PixelMap, focusX?: number, focusY?: number): Promise<void> 593e41f4b71Sopenharmony_ci 594e41f4b71Sopenharmony_ci设置自定义光标样式,使用Promise异步方式返回结果。 595e41f4b71Sopenharmony_ci 596e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.MultimodalInput.Input.Pointer 597e41f4b71Sopenharmony_ci 598e41f4b71Sopenharmony_ci**参数**: 599e41f4b71Sopenharmony_ci 600e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 601e41f4b71Sopenharmony_ci| ----- | ------ | ---- | ----------------------------------- | 602e41f4b71Sopenharmony_ci| windowId | number | 是 | 窗口id。 | 603e41f4b71Sopenharmony_ci| pixelMap | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | 是 | 自定义光标资源。 | 604e41f4b71Sopenharmony_ci| focusX | number | 否 | 自定义光标焦点x, 取值范围:大于等于0,默认为0。 | 605e41f4b71Sopenharmony_ci| focusY | number | 否 | 自定义光标焦点y,取值范围:大于等于0,默认为0。 | 606e41f4b71Sopenharmony_ci 607e41f4b71Sopenharmony_ci**返回值**: 608e41f4b71Sopenharmony_ci 609e41f4b71Sopenharmony_ci| 参数 | 说明 | 610e41f4b71Sopenharmony_ci| ------------------- | ---------------- | 611e41f4b71Sopenharmony_ci| Promise<void> | 无返回结果的Promise对象。 | 612e41f4b71Sopenharmony_ci 613e41f4b71Sopenharmony_ci**错误码**: 614e41f4b71Sopenharmony_ci 615e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 616e41f4b71Sopenharmony_ci 617e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 618e41f4b71Sopenharmony_ci| ---- | --------------------- | 619e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 620e41f4b71Sopenharmony_ci 621e41f4b71Sopenharmony_ci**示例**: 622e41f4b71Sopenharmony_ci 623e41f4b71Sopenharmony_ci```js 624e41f4b71Sopenharmony_ciimport { image } from '@kit.ImageKit'; 625e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 626e41f4b71Sopenharmony_ciimport { window } from '@kit.ArkUI'; 627e41f4b71Sopenharmony_cigetContext().resourceManager.getMediaContent($r("app.media.app_icon")).then((svgFileData) => { 628e41f4b71Sopenharmony_ci const svgBuffer: ArrayBuffer = svgFileData.buffer.slice(0); 629e41f4b71Sopenharmony_ci let svgImagesource: image.ImageSource = image.createImageSource(svgBuffer); 630e41f4b71Sopenharmony_ci let svgDecodingOptions: image.DecodingOptions = {desiredSize: { width: 50, height:50 }}; 631e41f4b71Sopenharmony_ci svgImagesource.createPixelMap(svgDecodingOptions).then((pixelMap) => { 632e41f4b71Sopenharmony_ci window.getLastWindow(getContext(), (error: BusinessError, win: window.Window) => { 633e41f4b71Sopenharmony_ci let windowId = win.getWindowProperties().id; 634e41f4b71Sopenharmony_ci try { 635e41f4b71Sopenharmony_ci pointer.setCustomCursor(windowId, pixelMap).then(() => { 636e41f4b71Sopenharmony_ci console.log(`setCustomCursor success`); 637e41f4b71Sopenharmony_ci }); 638e41f4b71Sopenharmony_ci } catch (error) { 639e41f4b71Sopenharmony_ci console.log(`setCustomCursor failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 640e41f4b71Sopenharmony_ci } 641e41f4b71Sopenharmony_ci }); 642e41f4b71Sopenharmony_ci }); 643e41f4b71Sopenharmony_ci}); 644e41f4b71Sopenharmony_ci``` 645e41f4b71Sopenharmony_ci 646e41f4b71Sopenharmony_ci## pointer.setCustomCursorSync<sup>11+</sup> 647e41f4b71Sopenharmony_ci 648e41f4b71Sopenharmony_cisetCustomCursorSync(windowId: number, pixelMap: image.PixelMap, focusX?: number, focusY?: number): void 649e41f4b71Sopenharmony_ci 650e41f4b71Sopenharmony_ci设置自定义光标样式,使用同步方式进行设置。 651e41f4b71Sopenharmony_ci 652e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.MultimodalInput.Input.Pointer 653e41f4b71Sopenharmony_ci 654e41f4b71Sopenharmony_ci**参数**: 655e41f4b71Sopenharmony_ci 656e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 657e41f4b71Sopenharmony_ci| ----- | ------ | ---- | ----------------------------------- | 658e41f4b71Sopenharmony_ci| windowId | number | 是 | 窗口id。 | 659e41f4b71Sopenharmony_ci| pixelMap | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | 是 | 自定义光标资源。 | 660e41f4b71Sopenharmony_ci| focusX | number | 否 | 自定义光标焦点x, 取值范围:大于等于0,默认为0。 | 661e41f4b71Sopenharmony_ci| focusY | number | 否 | 自定义光标焦点y,取值范围:大于等于0,默认为0。 | 662e41f4b71Sopenharmony_ci 663e41f4b71Sopenharmony_ci**错误码**: 664e41f4b71Sopenharmony_ci 665e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 666e41f4b71Sopenharmony_ci 667e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 668e41f4b71Sopenharmony_ci| ---- | --------------------- | 669e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 670e41f4b71Sopenharmony_ci 671e41f4b71Sopenharmony_ci**示例**: 672e41f4b71Sopenharmony_ci 673e41f4b71Sopenharmony_ci```js 674e41f4b71Sopenharmony_ciimport { image } from '@kit.ImageKit'; 675e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 676e41f4b71Sopenharmony_ciimport { window } from '@kit.ArkUI'; 677e41f4b71Sopenharmony_ciconst svgFileData = getContext().resourceManager.getMediaContent($r("app.media.app_icon")).then((svgFileData) => { 678e41f4b71Sopenharmony_ci const svgBuffer: ArrayBuffer = svgFileData.buffer.slice(0); 679e41f4b71Sopenharmony_ci let svgImagesource: image.ImageSource = image.createImageSource(svgBuffer); 680e41f4b71Sopenharmony_ci let svgDecodingOptions: image.DecodingOptions = {desiredSize: { width: 50, height:50 }}; 681e41f4b71Sopenharmony_ci svgImagesource.createPixelMap(svgDecodingOptions).then((pixelMap) => { 682e41f4b71Sopenharmony_ci window.getLastWindow(getContext(), (error: BusinessError, win: window.Window) => { 683e41f4b71Sopenharmony_ci let windowId = win.getWindowProperties().id; 684e41f4b71Sopenharmony_ci try { 685e41f4b71Sopenharmony_ci pointer.setCustomCursorSync(windowId, pixelMap, 25, 25); 686e41f4b71Sopenharmony_ci console.log(`setCustomCursorSync success`); 687e41f4b71Sopenharmony_ci } catch (error) { 688e41f4b71Sopenharmony_ci console.log(`setCustomCursorSync failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 689e41f4b71Sopenharmony_ci } 690e41f4b71Sopenharmony_ci }); 691e41f4b71Sopenharmony_ci }); 692e41f4b71Sopenharmony_ci}); 693e41f4b71Sopenharmony_ci```