1e41f4b71Sopenharmony_ci# Mouse Pointer Development
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci## When to Use
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ciMouse pointer management provides the functions such as displaying or hiding the mouse pointer as well as querying and setting the pointer style. For example, you can determine whether to display or hide the mouse pointer when a user watches a video in full screen, and can switch the mouse pointer to a color picker when a user attempts color pickup.
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ci## Modules to Import
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci```js
10e41f4b71Sopenharmony_ciimport { pointer } from '@kit.InputKit';
11e41f4b71Sopenharmony_ci```
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci## Available APIs
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ciThe following table lists the common APIs for mouse pointer management. For details about the APIs, see [ohos.multimodalInput.pointer](../../reference/apis-input-kit/js-apis-pointer.md).
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci| API                                                      | Description                                                        |
18e41f4b71Sopenharmony_ci| ------------------------------------------ | ------------------------------------------------------- |
19e41f4b71Sopenharmony_ci| isPointerVisible(callback: AsyncCallback\<boolean>): void | Checks the visible status of the mouse pointer.                                |
20e41f4b71Sopenharmony_ci| setPointerVisible(visible: boolean, callback: AsyncCallback\<void>): void | Sets the visible status of the mouse pointer. This setting takes effect for the mouse pointer globally.|
21e41f4b71Sopenharmony_ci| setPointerStyle(windowId: number, pointerStyle: PointerStyle, callback: AsyncCallback\<void>): void | Sets the mouse pointer style. This setting takes effect for the mouse pointer style of a specified window.        |
22e41f4b71Sopenharmony_ci| getPointerStyle(windowId: number, callback: AsyncCallback\<PointerStyle>): void | Obtains the mouse pointer style.                                          |
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ci## Hiding the Mouse Pointer
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ciWhen watching a video in full-screen mode, a user can hide the mouse pointer for an improved user experience.
27e41f4b71Sopenharmony_ci
28e41f4b71Sopenharmony_ci### How to Develop
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ci1. Switch to the full-screen playback mode.
31e41f4b71Sopenharmony_ci2. Hide the mouse pointer.
32e41f4b71Sopenharmony_ci3. Exit the full-screen playback mode.
33e41f4b71Sopenharmony_ci4. Display the mouse pointer.
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci```js
36e41f4b71Sopenharmony_ciimport { pointer } from '@kit.InputKit';
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci// 1. Switch to the full-screen playback mode.
39e41f4b71Sopenharmony_ci// 2. Hide the mouse pointer.
40e41f4b71Sopenharmony_citry {
41e41f4b71Sopenharmony_ci  pointer.setPointerVisible(false, (error: Error) => {
42e41f4b71Sopenharmony_ci    if (error) {
43e41f4b71Sopenharmony_ci      console.log(`Set pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
44e41f4b71Sopenharmony_ci      return;
45e41f4b71Sopenharmony_ci    }
46e41f4b71Sopenharmony_ci    console.log(`Set pointer visible success.`);
47e41f4b71Sopenharmony_ci  });
48e41f4b71Sopenharmony_ci} catch (error) {
49e41f4b71Sopenharmony_ci  console.log(`The mouse pointer hide attributes is failed. ${JSON.stringify(error, [`code`, `message`])}`);
50e41f4b71Sopenharmony_ci}
51e41f4b71Sopenharmony_ci
52e41f4b71Sopenharmony_ci// 3. Exit the full-screen playback mode.
53e41f4b71Sopenharmony_ci// 4. Display the mouse pointer.
54e41f4b71Sopenharmony_citry {
55e41f4b71Sopenharmony_ci  pointer.setPointerVisible(true, (error: Error) => {
56e41f4b71Sopenharmony_ci    if (error) {
57e41f4b71Sopenharmony_ci      console.log(`Set pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
58e41f4b71Sopenharmony_ci      return;
59e41f4b71Sopenharmony_ci    }
60e41f4b71Sopenharmony_ci    console.log(`Set pointer visible success.`);
61e41f4b71Sopenharmony_ci  });
62e41f4b71Sopenharmony_ci} catch (error) {
63e41f4b71Sopenharmony_ci  console.log(`Set pointer visible failed, ${JSON.stringify(error, [`code`, `message`])}`);
64e41f4b71Sopenharmony_ci}
65e41f4b71Sopenharmony_ci```
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_ci## Setting the Mouse Pointer Style
68e41f4b71Sopenharmony_ci
69e41f4b71Sopenharmony_ciWhen designing a color picker, you can have the mouse pointer switched to the color picker style during color pickup and then switched to the default style on completion of color pickup. This setting takes effect for the pointer style of a specified window in the current application. A total of 43 pointer styles can be set. For details, see [Pointer Style](../../reference/apis-input-kit/js-apis-pointer.md#pointerstyle).
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ci### How to Develop
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ci1. Enable the color pickup function.
74e41f4b71Sopenharmony_ci2. Obtain the window ID.
75e41f4b71Sopenharmony_ci3. Set the mouse pointer to the color picker style.
76e41f4b71Sopenharmony_ci4. End color pickup.
77e41f4b71Sopenharmony_ci5. Set the mouse pointer to the default style.
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_ci```js
80e41f4b71Sopenharmony_ciimport { pointer } from '@kit.InputKit';
81e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
82e41f4b71Sopenharmony_ciimport { window } from '@kit.ArkUI';
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci// 1. Enable the color pickup function.
85e41f4b71Sopenharmony_ci// 2. Obtain the window ID.
86e41f4b71Sopenharmony_ciwindow.getLastWindow(getContext(), (error: BusinessError, windowClass: window.Window) => {
87e41f4b71Sopenharmony_ci  if (error.code) {
88e41f4b71Sopenharmony_ci    console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(error));
89e41f4b71Sopenharmony_ci    return;
90e41f4b71Sopenharmony_ci  }
91e41f4b71Sopenharmony_ci  let windowId = windowClass.getWindowProperties().id;
92e41f4b71Sopenharmony_ci  if (windowId < 0) {
93e41f4b71Sopenharmony_ci    console.log(`Invalid windowId`);
94e41f4b71Sopenharmony_ci    return;
95e41f4b71Sopenharmony_ci  }
96e41f4b71Sopenharmony_ci  try {
97e41f4b71Sopenharmony_ci    // 3. Set the mouse pointer to the color picker style.
98e41f4b71Sopenharmony_ci    pointer.setPointerStyle(windowId, pointer.PointerStyle.COLOR_SUCKER).then(() => {
99e41f4b71Sopenharmony_ci      console.log(`Successfully set mouse pointer style`);
100e41f4b71Sopenharmony_ci    });
101e41f4b71Sopenharmony_ci  } catch (error) {
102e41f4b71Sopenharmony_ci    console.log(`Failed to set the pointer style, error=${JSON.stringify(error)}, msg=${JSON.stringify(`message`)}`);
103e41f4b71Sopenharmony_ci  }
104e41f4b71Sopenharmony_ci});
105e41f4b71Sopenharmony_ci// 4. End color pickup.
106e41f4b71Sopenharmony_ciwindow.getLastWindow(getContext(), (error: BusinessError, windowClass: window.Window) => {
107e41f4b71Sopenharmony_ci  if (error.code) {
108e41f4b71Sopenharmony_ci    console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(error));
109e41f4b71Sopenharmony_ci    return;
110e41f4b71Sopenharmony_ci  }
111e41f4b71Sopenharmony_ci  let windowId = windowClass.getWindowProperties().id;
112e41f4b71Sopenharmony_ci  if (windowId < 0) {
113e41f4b71Sopenharmony_ci    console.log(`Invalid windowId`);
114e41f4b71Sopenharmony_ci    return;
115e41f4b71Sopenharmony_ci  }
116e41f4b71Sopenharmony_ci  try {
117e41f4b71Sopenharmony_ci    // 5. Set the mouse pointer to the default style.
118e41f4b71Sopenharmony_ci    pointer.setPointerStyle(windowId, pointer.PointerStyle.DEFAULT).then(() => {
119e41f4b71Sopenharmony_ci      console.log(`Successfully set mouse pointer style`);
120e41f4b71Sopenharmony_ci    });
121e41f4b71Sopenharmony_ci  } catch (error) {
122e41f4b71Sopenharmony_ci    console.log(`Failed to set the pointer style, error=${JSON.stringify(error)}, msg=${JSON.stringify(`message`)}`);
123e41f4b71Sopenharmony_ci  }
124e41f4b71Sopenharmony_ci});
125e41f4b71Sopenharmony_ci```
126