• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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&lt;void&gt;): 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&lt;void&gt; | 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&lt;void&gt;
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&lt;void&gt; | 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&lt;boolean&gt;): 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&lt;boolean&gt; | 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&lt;boolean&gt;
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&lt;boolean&gt; | 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&lt;void&gt;): 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&lt;void&gt; | 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&lt;void&gt;
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&lt;void&gt; | 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&lt;number&gt;): 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&lt;number&gt; | 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&lt;number&gt;
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&lt;number&gt; | 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&lt;PointerStyle&gt;): 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&lt;[PointerStyle](#pointerstyle9)&gt; | 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&lt;PointerStyle&gt;
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&lt;[PointerStyle](#pointerstyle9)&gt; | 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&lt;void&gt;): 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&lt;void&gt;      | 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&lt;void&gt;
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&lt;void&gt; | 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     |![Default.png](./figures/Default.png)|
435| EAST                             | 1    | East arrow  |![East.png](./figures/East.png)|
436| WEST                             | 2    | West arrow  |![West.png](./figures/West.png)|
437| SOUTH                            | 3    | South arrow  |![South.png](./figures/South.png)|
438| NORTH                            | 4    | North arrow  |![North.png](./figures/North.png)|
439| WEST_EAST                        | 5    | West-east arrow |![West_East.png](./figures/West_East.png)|
440| NORTH_SOUTH                      | 6    | North-south arrow |![North_South.png](./figures/North_South.png)|
441| NORTH_EAST                       | 7    | North-east arrow |![North_East.png](./figures/North_East.png)|
442| NORTH_WEST                       | 8    | North-west arrow |![North_West.png](./figures/North_West.png)|
443| SOUTH_EAST                       | 9    | South-east arrow |![South_East.png](./figures/South_East.png)|
444| SOUTH_WEST                       | 10   | South-west arrow |![South_West.png](./figures/South_West.png)|
445| NORTH_EAST_SOUTH_WEST            | 11   | North-east and south-west adjustment|![North_East_South_West.png](./figures/North_East_South_West.png)|
446| NORTH_WEST_SOUTH_EAST            | 12   | North-west and south-east adjustment|![North_West_South_East.png](./figures/North_West_South_East.png)|
447| CROSS                            | 13   | Cross (accurate selection)  |![Cross.png](./figures/Cross.png)|
448| CURSOR_COPY                      | 14   | Copy cursor    |![Copy.png](./figures/Copy.png)|
449| CURSOR_FORBID                    | 15   | Forbid cursor   |![Forbid.png](./figures/Forbid.png)|
450| COLOR_SUCKER                     | 16   | Sucker    |![Colorsucker.png](./figures/Colorsucker.png)|
451| HAND_GRABBING                    | 17   | Grabbing hand  |![Hand_Grabbing.png](./figures/Hand_Grabbing.png)|
452| HAND_OPEN                        | 18   | Opening hand  |![Hand_Open.png](./figures/Hand_Open.png)|
453| HAND_POINTING                    | 19   | Hand-shaped pointer  |![Hand_Poniting.png](./figures/Hand_Pointing.png)|
454| HELP                             | 20   | Help   |![Help.png](./figures/Help.png)|
455| MOVE                             | 21   | Move    |![Move.png](./figures/Move.png)|
456| RESIZE_LEFT_RIGHT                | 22   | Left and right resizing|![Resize_Left_Right.png](./figures/Resize_Left_Right.png)|
457| RESIZE_UP_DOWN                   | 23   | Up and down resizing|![Resize_Up_Down.png](./figures/Resize_Up_Down.png)|
458| SCREENSHOT_CHOOSE                | 24   | Screenshot crosshair|![Screenshot_Cross.png](./figures/Screenshot_Cross.png)|
459| SCREENSHOT_CURSOR                | 25   | Screenshot cursor    |![Screenshot_Cursor.png](./figures/Screenshot_Cursor.png)|
460| TEXT_CURSOR                      | 26   | Text cursor  |![Text_Cursor.png](./figures/Text_Cursor.png)|
461| ZOOM_IN                          | 27   | Zoom in    |![Zoom_In.png](./figures/Zoom_In.png)|
462| ZOOM_OUT                         | 28   | Zoom out    |![Zoom_Out.png](./figures/Zoom_Out.png)|
463| MIDDLE_BTN_EAST                  | 29   | Scrolling east  |![MID_Btn_East.png](./figures/MID_Btn_East.png)|
464| MIDDLE_BTN_WEST                  | 30   | Scrolling west  |![MID_Btn_West.png](./figures/MID_Btn_West.png)|
465| MIDDLE_BTN_SOUTH                 | 31   | Scrolling south  | ![MID_Btn_South.png](./figures/MID_Btn_South.png)            |
466| MIDDLE_BTN_NORTH                 | 32   | Scrolling north  |![MID_Btn_North.png](./figures/MID_Btn_North.png)|
467| MIDDLE_BTN_NORTH_SOUTH           | 33   | Scrolling north-south |![MID_Btn_North_South.png](./figures/MID_Btn_North_South.png)|
468| MIDDLE_BTN_NORTH_EAST            | 34   | Scrolling north-east |![MID_Btn_North_East.png](./figures/MID_Btn_North_East.png)|
469| MIDDLE_BTN_NORTH_WEST            | 35   | Scrolling north-west |![MID_Btn_North_West.png](./figures/MID_Btn_North_West.png)|
470| MIDDLE_BTN_SOUTH_EAST            | 36   | Scrolling south-east |![MID_Btn_South_East.png](./figures/MID_Btn_South_East.png)|
471| MIDDLE_BTN_SOUTH_WEST            | 37   | Scrolling south-west |![MID_Btn_South_West.png](./figures/MID_Btn_South_West.png)|
472| MIDDLE_BTN_NORTH_SOUTH_WEST_EAST | 38   | Moving as a cone in four directions|![MID_Btn_North_South_West_East.png](./figures/MID_Btn_North_South_West_East.png)|
473