1# @ohos.multimodalInput.pointer (Mouse Pointer) 2 3The **pointer** module provides APIs related to pointer attribute management. 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8 9## Modules to Import 10 11```js 12import pointer from '@ohos.multimodalInput.pointer'; 13``` 14 15## pointer.setPointerVisible<sup>9+</sup> 16 17setPointerVisible(visible: boolean, callback: AsyncCallback<void>): void 18 19Sets the visible status of the mouse pointer. This API uses an asynchronous callback to return the result. 20 21**System capability**: SystemCapability.MultimodalInput.Input.Pointer 22 23**Parameters** 24 25| Name | Type | Mandatory | Description | 26| -------- | ------------------------- | ---- | ---------------------------------------- | 27| visible | boolean | Yes | Whether the mouse pointer is visible.| 28| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 29 30**Example** 31 32```js 33try { 34 pointer.setPointerVisible(true, (error) => { 35 if (error) { 36 console.log(`Set pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 37 return; 38 } 39 console.log(`Set pointer visible success`); 40 }); 41} catch (error) { 42 console.log(`Set pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 43} 44``` 45 46## pointer.setPointerVisible<sup>9+</sup> 47 48setPointerVisible(visible: boolean): Promise<void> 49 50Sets the visible status of the mouse pointer. This API uses a promise to return the result. 51 52**System capability**: SystemCapability.MultimodalInput.Input.Pointer 53 54**Parameters** 55 56| Name | Type | Mandatory | Description | 57| ------- | ------- | ---- | ---------------------------------------- | 58| visible | boolean | Yes | Whether the mouse pointer is visible.| 59 60**Return value** 61 62| Name | Description | 63| ------------------- | ------------------- | 64| Promise<void> | Promise used to return the result.| 65 66**Example** 67 68```js 69try { 70 pointer.setPointerVisible(false).then(() => { 71 console.log(`Set pointer visible success`); 72 }); 73} catch (error) { 74 console.log(`Set pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 75} 76``` 77 78## pointer.isPointerVisible<sup>9+</sup> 79 80isPointerVisible(callback: AsyncCallback<boolean>): void 81 82Checks the visible status of the mouse pointer. This API uses an asynchronous callback to return the result. 83 84**System capability**: SystemCapability.MultimodalInput.Input.Pointer 85 86**Parameters** 87 88| Name | Type | Mandatory | Description | 89| -------- | ---------------------------- | ---- | -------------- | 90| callback | AsyncCallback<boolean> | Yes | Callback used to return the result.| 91 92**Example** 93 94```js 95try { 96 pointer.isPointerVisible((error, visible) => { 97 if (error) { 98 console.log(`Get pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 99 return; 100 } 101 console.log(`Get pointer visible success, visible: ${JSON.stringify(visible)}`); 102 }); 103} catch (error) { 104 console.log(`Get pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 105} 106``` 107 108## pointer.isPointerVisible<sup>9+</sup> 109 110isPointerVisible(): Promise<boolean> 111 112Checks the visible status of the mouse pointer. This API uses a promise to return the result. 113 114**System capability**: SystemCapability.MultimodalInput.Input.Pointer 115 116**Return value** 117 118| Name | Description | 119| ---------------------- | ------------------- | 120| Promise<boolean> | Promise used to return the result.| 121 122**Example** 123 124```js 125try { 126 pointer.isPointerVisible().then((visible) => { 127 console.log(`Get pointer visible success, visible: ${JSON.stringify(visible)}`); 128 }); 129} catch (error) { 130 console.log(`Get pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 131} 132``` 133 134## pointer.setPointerSpeed<sup>9+</sup> 135 136setPointerSpeed(speed: number, callback: AsyncCallback<void>): void 137 138Sets the mouse movement speed. This API uses an asynchronous callback to return the result. 139 140**System capability**: SystemCapability.MultimodalInput.Input.Pointer 141 142**System API**: This is a system API. 143 144**Parameters** 145 146| Name | Type | Mandatory | Description | 147| -------- | ------------------------- | ---- | ------------------------------------- | 148| speed | number | Yes | Mouse movement speed. The value ranges from **1** to **11**. The default value is **5**. | 149| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 150 151**Example** 152 153```js 154try { 155 pointer.setPointerSpeed(5, (error) => { 156 if (error) { 157 console.log(`Set pointer speed failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 158 return; 159 } 160 console.log(`Set pointer speed success`); 161 }); 162} catch (error) { 163 console.log(`Set pointer speed failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 164} 165``` 166 167## pointer.setPointerSpeed<sup>9+</sup> 168 169setPointerSpeed(speed: number): Promise<void> 170 171Sets the mouse movement speed. This API uses a promise to return the result. 172 173**System capability**: SystemCapability.MultimodalInput.Input.Pointer 174 175**System API**: This is a system API. 176 177**Parameters** 178 179| Name | Type | Mandatory | Description | 180| ----- | ------ | ---- | ----------------------------------- | 181| speed | number | Yes | Mouse movement speed. The value ranges from **1** to **11**. The default value is **5**.| 182 183**Return value** 184 185| Name | Description | 186| ------------------- | ---------------- | 187| Promise<void> | Promise used to return the result.| 188 189**Example** 190 191```js 192try { 193 pointer.setPointerSpeed(5).then(() => { 194 console.log(`Set pointer speed success`); 195 }); 196} catch (error) { 197 console.log(`Set pointer speed failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 198} 199``` 200 201## pointer.getPointerSpeed<sup>9+</sup> 202 203getPointerSpeed(callback: AsyncCallback<number>): void 204 205Obtains the mouse movement speed. This API uses an asynchronous callback to return the result. 206 207**System capability**: SystemCapability.MultimodalInput.Input.Pointer 208 209**System API**: This is a system API. 210 211**Parameters** 212 213| Name | Type | Mandatory | Description | 214| -------- | --------------------------- | ---- | -------------- | 215| callback | AsyncCallback<number> | Yes | Callback used to return the result.| 216 217**Example** 218 219```js 220try { 221 pointer.getPointerSpeed((error, speed) => { 222 if (error) { 223 console.log(`Get pointer speed failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 224 return; 225 } 226 console.log(`Get pointer speed success, speed: ${JSON.stringify(speed)}`); 227 }); 228} catch (error) { 229 console.log(`Get pointer speed failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 230} 231``` 232 233## pointer.getPointerSpeed<sup>9+</sup> 234 235getPointerSpeed(): Promise<number> 236 237Obtains the mouse movement speed. This API uses a promise to return the result. 238 239**System capability**: SystemCapability.MultimodalInput.Input.Pointer 240 241**System API**: This is a system API. 242 243**Return value** 244 245| Name | Description | 246| --------------------- | ------------------- | 247| Promise<number> | Promise used to return the result.| 248 249**Example** 250 251```js 252try { 253 pointer.getPointerSpeed().then(speed => { 254 console.log(`Get pointer speed success, speed: ${JSON.stringify(speed)}`); 255 }); 256} catch (error) { 257 console.log(`Get pointer speed failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 258} 259``` 260 261## pointer.getPointerStyle<sup>9+</sup> 262 263getPointerStyle(windowId: number, callback: AsyncCallback<PointerStyle>): void 264 265Obtains the mouse pointer style. This API uses an asynchronous callback to return the result. 266 267**System capability**: SystemCapability.MultimodalInput.Input.Pointer 268 269**Parameters** 270 271| Name | Type | Mandatory | Description | 272| -------- | ---------------------------------------- | ---- | -------------- | 273| windowId | number | Yes | Window ID. | 274| callback | AsyncCallback<[PointerStyle](#pointerstyle9)> | Yes | Callback used to return the result.| 275 276**Example** 277 278```js 279import window from '@ohos.window'; 280 281window.getLastWindow(this.context, (error, win) => { 282 if (error.code) { 283 console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(error)); 284 return; 285 } 286 let windowId = win.getWindowProperties().id; 287 if (windowId < 0) { 288 console.log(`Invalid windowId`); 289 return; 290 } 291 try { 292 pointer.getPointerStyle(windowId, (error, style) => { 293 console.log(`Get pointer style success, style: ${JSON.stringify(style)}`); 294 }); 295 } catch (error) { 296 console.log(`Get pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 297 } 298}); 299``` 300 301## pointer.getPointerStyle<sup>9+</sup> 302 303getPointerStyle(windowId: number): Promise<PointerStyle> 304 305Obtains the mouse pointer style. This API uses a promise to return the result. 306 307**System capability**: SystemCapability.MultimodalInput.Input.Pointer 308 309**Parameters** 310 311| Name | Type | Mandatory| Description | 312| -------- | ------ | ---- | -------- | 313| windowId | number | Yes | Window ID.| 314 315**Return value** 316 317| Name | Description | 318| ---------------------------------------- | ------------------- | 319| Promise<[PointerStyle](#pointerstyle9)> | Promise used to return the result.| 320 321**Example** 322 323```js 324import window from '@ohos.window'; 325 326window.getLastWindow(this.context, (error, win) => { 327 if (error.code) { 328 console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(error)); 329 return; 330 } 331 let windowId = win.getWindowProperties().id; 332 if (windowId < 0) { 333 console.log(`Invalid windowId`); 334 return; 335 } 336 try { 337 pointer.getPointerStyle(windowId).then((style) => { 338 console.log(`Get pointer style success, style: ${JSON.stringify(style)}`); 339 }); 340 } catch (error) { 341 console.log(`Get pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 342 } 343}); 344``` 345 346## pointer.setPointerStyle<sup>9+</sup> 347 348setPointerStyle(windowId: number, pointerStyle: PointerStyle, callback: AsyncCallback<void>): void 349 350Sets the mouse pointer style. This API uses an asynchronous callback to return the result. 351 352**System capability**: SystemCapability.MultimodalInput.Input.Pointer 353 354**Parameters** 355 356| Name | Type | Mandatory | Description | 357| ------------ | ------------------------------ | ---- | ----------------------------------- | 358| windowId | number | Yes | Window ID. | 359| pointerStyle | [PointerStyle](#pointerstyle9) | Yes | Mouse pointer style ID. | 360| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 361 362**Example** 363 364```js 365import window from '@ohos.window'; 366 367window.getLastWindow(this.context, (error, win) => { 368 if (error.code) { 369 console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(error)); 370 return; 371 } 372 let windowId = win.getWindowProperties().id; 373 if (windowId < 0) { 374 console.log(`Invalid windowId`); 375 return; 376 } 377 try { 378 pointer.setPointerStyle(windowId, pointer.PointerStyle.CROSS, error => { 379 console.log(`Set pointer style success`); 380 }); 381 } catch (error) { 382 console.log(`Set pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 383 } 384}); 385``` 386## pointer.setPointerStyle<sup>9+</sup> 387 388setPointerStyle(windowId: number, pointerStyle: PointerStyle): Promise<void> 389 390Sets the mouse pointer style. This API uses a promise to return the result. 391 392**System capability**: SystemCapability.MultimodalInput.Input.Pointer 393 394**Parameters** 395 396| Name | Type | Mandatory | Description | 397| ------------------- | ------------------------------ | ---- | ---------------- | 398| windowId | number | Yes | Window ID. | 399| pointerStyle | [PointerStyle](#pointerstyle9) | Yes | Mouse pointer style ID. | 400| Promise<void> | void | Yes | Promise used to return the result.| 401 402**Example** 403 404```js 405import window from '@ohos.window'; 406 407window.getLastWindow(this.context, (error, win) => { 408 if (error.code) { 409 console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(error)); 410 return; 411 } 412 let windowId = win.getWindowProperties().id; 413 if (windowId < 0) { 414 console.log(`Invalid windowId`); 415 return; 416 } 417 try { 418 pointer.setPointerStyle(windowId, pointer.PointerStyle.CROSS).then(() => { 419 console.log(`Set pointer style success`); 420 }); 421 } catch (error) { 422 console.log(`Set pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 423 } 424}); 425``` 426## PointerStyle<sup>9+</sup> 427 428Enumerates mouse pointer styles. 429 430**System capability**: SystemCapability.MultimodalInput.Input.Pointer 431 432| Name | Value | Description |Legend| 433| -------------------------------- | ---- | ------ |------ | 434| DEFAULT | 0 | Default || 435| EAST | 1 | East arrow || 436| WEST | 2 | West arrow || 437| SOUTH | 3 | South arrow || 438| NORTH | 4 | North arrow || 439| WEST_EAST | 5 | West-east arrow || 440| NORTH_SOUTH | 6 | North-south arrow || 441| NORTH_EAST | 7 | North-east arrow || 442| NORTH_WEST | 8 | North-west arrow || 443| SOUTH_EAST | 9 | South-east arrow || 444| SOUTH_WEST | 10 | South-west arrow || 445| NORTH_EAST_SOUTH_WEST | 11 | North-east and south-west adjustment|| 446| NORTH_WEST_SOUTH_EAST | 12 | North-west and south-east adjustment|| 447| CROSS | 13 | Cross (accurate selection) || 448| CURSOR_COPY | 14 | Copy cursor || 449| CURSOR_FORBID | 15 | Forbid cursor || 450| COLOR_SUCKER | 16 | Sucker || 451| HAND_GRABBING | 17 | Grabbing hand || 452| HAND_OPEN | 18 | Opening hand || 453| HAND_POINTING | 19 | Hand-shaped pointer || 454| HELP | 20 | Help || 455| MOVE | 21 | Move || 456| RESIZE_LEFT_RIGHT | 22 | Left and right resizing|| 457| RESIZE_UP_DOWN | 23 | Up and down resizing|| 458| SCREENSHOT_CHOOSE | 24 | Screenshot crosshair|| 459| SCREENSHOT_CURSOR | 25 | Screenshot cursor || 460| TEXT_CURSOR | 26 | Text cursor || 461| ZOOM_IN | 27 | Zoom in || 462| ZOOM_OUT | 28 | Zoom out || 463| MIDDLE_BTN_EAST | 29 | Scrolling east || 464| MIDDLE_BTN_WEST | 30 | Scrolling west || 465| MIDDLE_BTN_SOUTH | 31 | Scrolling south |  | 466| MIDDLE_BTN_NORTH | 32 | Scrolling north || 467| MIDDLE_BTN_NORTH_SOUTH | 33 | Scrolling north-south || 468| MIDDLE_BTN_NORTH_EAST | 34 | Scrolling north-east || 469| MIDDLE_BTN_NORTH_WEST | 35 | Scrolling north-west || 470| MIDDLE_BTN_SOUTH_EAST | 36 | Scrolling south-east || 471| MIDDLE_BTN_SOUTH_WEST | 37 | Scrolling south-west || 472| MIDDLE_BTN_NORTH_SOUTH_WEST_EAST | 38 | Moving as a cone in four directions|| 473