1# @ohos.multimodalInput.inputMonitor (输入监听)(系统接口)
2
3输入监听模块,提供了监听输入设备事件的能力。输入设备事件当前包括触摸(触屏)事件、鼠标输入事件和触控板输入事件。
4
5>**说明:**
6>
7>- 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8>
9>- 文档中“全局”表示整个触控屏或触控板。如监听全局触摸事件,表示触摸触控板任何位置时,整个触控板的触摸事件均被监听。
10>
11>- 本模块接口均为系统接口。
12
13## 导入模块
14
15```js
16import { inputMonitor } from '@kit.InputKit';
17```
18
19## inputMonitor.on('touch')
20
21on(type: 'touch', receiver: TouchEventReceiver): void
22
23监听全局触摸(触屏)事件。
24
25**需要权限:** ohos.permission.INPUT_MONITORING
26
27**系统能力:** SystemCapability.MultimodalInput.Input.InputMonitor
28
29**参数:**
30
31| 参数名       | 类型                                       | 必填   | 说明                  |
32| -------- | ---------------------------------------- | ---- | ------------------- |
33| type     | string                                   | 是    | 输入设备事件类型,取值'touch'。 |
34| receiver | [TouchEventReceiver](#toucheventreceiver) | 是    | 回调函数,异步上报触摸屏输入事件。 |
35
36**错误码**:
37
38以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
39
40| 错误码ID  | 错误信息             |
41| ---- | --------------------- |
42| 201  | Permission denied.   |
43| 401  | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
44
45**示例:**
46
47```js
48import { TouchEvent } from '@kit.InputKit';
49try {
50  inputMonitor.on('touch', (touchEvent: TouchEvent) => {
51    console.log(`Monitor on success ${JSON.stringify(touchEvent)}`);
52    return false;
53  });
54} catch (error) {
55  console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
56}
57```
58
59## inputMonitor.on('mouse')<sup>9+</sup>
60
61on(type: 'mouse', receiver: Callback&lt;MouseEvent&gt;): void
62
63监听全局鼠标事件。
64
65**需要权限:** ohos.permission.INPUT_MONITORING
66
67**系统能力:** SystemCapability.MultimodalInput.Input.InputMonitor
68
69**参数:**
70
71| 参数名       | 类型                         | 必填   | 说明                  |
72| -------- | -------------------------- | ---- | ------------------- |
73| type     | string                     | 是    | 输入设备事件类型,取值'mouse'。 |
74| receiver | Callback&lt;[MouseEvent](js-apis-mouseevent.md#mouseevent)&gt; | 是    | 回调函数,异步上报鼠标输入事件。  |
75
76**错误码**:
77
78以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
79
80| 错误码ID  | 错误信息             |
81| ---- | --------------------- |
82| 201  | Permission denied.   |
83| 401  | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
84
85**示例:**
86
87```js
88import { MouseEvent } from '@kit.InputKit';
89
90try {
91  inputMonitor.on('mouse', (mouseEvent: MouseEvent) => {
92    console.log(`Monitor on success ${JSON.stringify(mouseEvent)}`);
93    return false;
94  });
95} catch (error) {
96  console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
97}
98```
99
100## inputMonitor.on('mouse')<sup>11+</sup>
101
102on(type: 'mouse', rect: display.Rect[], receiver: Callback&lt;MouseEvent&gt;): void
103
104监听鼠标事件,当鼠标移动至指定矩形区域内时,触发回调任务。
105
106**需要权限:** ohos.permission.INPUT_MONITORING
107
108**系统能力:** SystemCapability.MultimodalInput.Input.InputMonitor
109
110**参数:**
111
112| 参数名       | 类型                         | 必填   | 说明                  |
113| -------- | -------------------------- | ---- | ------------------- |
114| type     | string                     | 是    | 输入设备事件类型,取值'mouse'。 |
115| rect     | display.Rect[]             | 是    | 可以触发回调任务的矩形区域,可传入1至2个。 |
116| receiver | Callback&lt;[MouseEvent](js-apis-mouseevent.md#mouseevent)&gt; | 是    | 回调函数,异步上报鼠标输入事件。  |
117
118**错误码**:
119
120以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
121
122| 错误码ID  | 错误信息             |
123| ---- | --------------------- |
124| 201  | Permission denied.   |
125| 202  | SystemAPI permission error.  |
126| 401  | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
127
128**示例:**
129
130```js
131import { MouseEvent } from '@kit.InputKit';
132import { promptAction } from '@kit.ArkUI';
133import { display } from '@kit.ArkUI';
134
135/**
136 * 鼠标在矩形区域内时,触发的回调任务。
137 */
138function callback(mouseEvent : MouseEvent) {
139  promptAction.showToast({
140    message: `监听成功:${JSON.stringify(mouseEvent)}`
141  })
142  console.log(`Monitor on success ${JSON.stringify(mouseEvent)}`);
143  return false;
144};
145
146/**
147 * 触发回调事件矩形区域。
148 */
149let rect: display.Rect[] = [{
150  left: 100,
151  top: 100,
152  width: 100,
153  height: 100
154}, {
155  left: 600,
156  top: 100,
157  width: 100,
158  height: 100
159}];
160
161try {
162  inputMonitor.on('mouse', rect, callback);
163} catch (error) {
164  console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
165}
166```
167
168## inputMonitor.off('touch')
169
170off(type: 'touch', receiver?: TouchEventReceiver): void
171
172取消监听全局触摸(触屏)事件。
173
174**需要权限:** ohos.permission.INPUT_MONITORING
175
176**系统能力:** SystemCapability.MultimodalInput.Input.InputMonitor
177
178**参数:**
179
180| 参数名       | 类型                                       | 必填   | 说明                  |
181| -------- | ---------------------------------------- | ---- | ------------------- |
182| type     | string                                   | 是    | 输入设备事件类型,取值'touch'。 |
183| receiver | [TouchEventReceiver](#toucheventreceiver) | 否    | 需要取消监听的回调函数。若不填,则取消当前应用监听的所有回调函数。  |
184
185**错误码**:
186
187以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
188
189| 错误码ID  | 错误信息             |
190| ---- | --------------------- |
191| 201  | Permission denied.   |
192| 401  | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
193
194**示例:**
195
196```js
197import { TouchEvent } from '@kit.InputKit';
198// 取消监听单个回调函数
199let callback = (touchEvent: TouchEvent) => {
200  console.log(`Monitor on success ${JSON.stringify(touchEvent)}`);
201  return false;
202};
203try {
204  inputMonitor.on('touch', callback);
205  inputMonitor.off('touch', callback);
206  console.log(`Monitor off success`);
207} catch (error) {
208  console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
209}
210```
211
212```js
213import { TouchEvent } from '@kit.InputKit';
214// 取消监听所有回调函数
215let callback = (touchEvent: TouchEvent) => {
216  console.log(`Monitor on success ${JSON.stringify(touchEvent)}`);
217  return false;
218};
219try {
220  inputMonitor.on('touch', callback);
221  inputMonitor.off('touch');
222  console.log(`Monitor off success`);
223} catch (error) {
224  console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
225}
226```
227
228## inputMonitor.off('mouse')<sup>9+</sup>
229
230off(type: 'mouse', receiver?: Callback&lt;MouseEvent&gt;): void
231
232取消监听全局鼠标事件。
233
234**需要权限:** ohos.permission.INPUT_MONITORING
235
236**系统能力:** SystemCapability.MultimodalInput.Input.InputMonitor
237
238**参数:**
239
240| 参数名       | 类型                         | 必填   | 说明                  |
241| -------- | -------------------------- | ---- | ------------------- |
242| type     | string                     | 是    | 输入设备事件类型,取值'mouse'。 |
243| receiver | Callback&lt;MouseEvent&gt; | 否    | 需要取消监听的回调函数。若不填,则取消当前应用监听的所有回调函数。 |
244
245**错误码**:
246
247以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
248
249| 错误码ID  | 错误信息             |
250| ---- | --------------------- |
251| 201  | Permission denied.   |
252| 401  | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
253
254**示例:**
255
256```js
257import { MouseEvent } from '@kit.InputKit';
258// 取消监听单个回调函数
259let callback = (mouseEvent: MouseEvent) => {
260  console.log(`Monitor on success ${JSON.stringify(mouseEvent)}`);
261  return false;
262};
263try {
264  inputMonitor.on('mouse', callback);
265  inputMonitor.off('mouse', callback);
266  console.log(`Monitor off success`);
267} catch (error) {
268  console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
269}
270```
271
272```js
273import { MouseEvent } from '@kit.InputKit';
274// 取消监听所有回调函数
275let callback = (mouseEvent: MouseEvent) => {
276  console.log(`Monitor on success ${JSON.stringify(mouseEvent)}`);
277  return false;
278};
279try {
280  inputMonitor.on('mouse', callback);
281  inputMonitor.off('mouse');
282  console.log(`Monitor off success`);
283} catch (error) {
284  console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
285}
286```
287
288## TouchEventReceiver
289
290(touchEvent: TouchEvent): Boolean
291
292触摸(触屏)输入事件的回调函数。
293
294**需要权限:** ohos.permission.INPUT_MONITORING
295
296**系统能力:** SystemCapability.MultimodalInput.Input.InputMonitor
297
298**参数:**
299
300| 参数名         | 类型                                       | 必填   | 说明                                       |
301| ---------- | ---------------------------------------- | ---- | ---------------------------------------- |
302| touchEvent | [TouchEvent](js-apis-touchevent.md#touchevent) | 是    | 触摸输入事件。 |
303
304**返回值:**
305
306| 类型      | 说明                                       |
307| ------- | ---------------------------------------- |
308| Boolean | 若返回true,本次触摸后续产生的事件不再分发到窗口;若返回false,本次触摸后续产生的事件还会分发到窗口。 |
309
310**示例:**
311
312```js
313import { TouchEvent } from '@kit.InputKit';
314try {
315  inputMonitor.on('touch', touchEvent => {
316    if (touchEvent.touches.length == 3) { // 当前有三个手指按下
317      return true;
318    }
319    return false;
320  });
321} catch (error) {
322    console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
323}
324```
325
326## inputMonitor.on('pinch')<sup>10+</sup>
327
328on(type: 'pinch', receiver: Callback&lt;[Pinch](js-apis-multimodalinput-gestureevent.md#pinch)&gt;): void
329
330监听全局触控板的捏合事件。
331
332**需要权限:** ohos.permission.INPUT_MONITORING
333
334**系统能力:** SystemCapability.MultimodalInput.Input.InputMonitor
335
336**参数:**
337
338| 参数名       | 类型                         | 必填   | 说明                  |
339| -------- | -------------------------- | ---- | ------------------- |
340| type     | string                     | 是    | 输入设备事件类型,取值'pinch'。 |
341| receiver | Callback&lt;[Pinch](js-apis-multimodalinput-gestureevent.md#pinch)&gt; | 是    | 回调函数,异步上报捏合输入事件。  |
342
343**错误码**:
344
345以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
346
347| 错误码ID  | 错误信息             |
348| ---- | --------------------- |
349| 201  | Permission denied.   |
350| 202  | SystemAPI permission error.  |
351| 401  | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
352
353**示例:**
354
355```js
356import type { Pinch } from '@kit.InputKit';
357try {
358  inputMonitor.on('pinch', (pinchEvent) => {
359    console.log(`Monitor on success ${JSON.stringify(pinchEvent)}`);
360    return false;
361  });
362} catch (error) {
363  console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
364}
365```
366
367## inputMonitor.off('pinch')<sup>10+</sup>
368
369off(type: 'pinch', receiver?: Callback&lt;[Pinch](js-apis-multimodalinput-gestureevent.md#pinch)&gt;): void
370
371取消监听全局触控板的捏合事件。
372
373**需要权限:** ohos.permission.INPUT_MONITORING
374
375**系统能力:** SystemCapability.MultimodalInput.Input.InputMonitor
376
377**参数:**
378
379| 参数名       | 类型                         | 必填   | 说明                  |
380| -------- | -------------------------- | ---- | ------------------- |
381| type     | string                     | 是    | 输入设备事件类型,取值'pinch'。 |
382| receiver | Callback&lt;[Pinch](js-apis-multimodalinput-gestureevent.md#pinch)&gt; | 否    | 需要取消监听的回调函数。若不填,则取消当前应用监听的所有回调函数。 |
383
384**错误码**:
385
386以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
387
388| 错误码ID  | 错误信息             |
389| ---- | --------------------- |
390| 201  | Permission denied.   |
391| 202  | SystemAPI permission error.  |
392| 401  | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
393
394**示例:**
395
396```js
397// 取消监听单个回调函数
398import { Pinch } from '@kit.InputKit';
399
400let callback = (pinchEvent: Pinch) => {
401  console.log(`Monitor on success ${JSON.stringify(pinchEvent)}`);
402  return false;
403};
404try {
405  inputMonitor.on('pinch', callback);
406  inputMonitor.off('pinch', callback);
407  console.log(`Monitor off success`);
408} catch (error) {
409  console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
410}
411```
412
413```js
414// 取消监听所有回调函数
415import { Pinch } from '@kit.InputKit';
416
417let callback = (pinchEvent: Pinch) => {
418  console.log(`Monitor on success ${JSON.stringify(pinchEvent)}`);
419  return false;
420};
421try {
422  inputMonitor.on('pinch', callback);
423  inputMonitor.off('pinch');
424  console.log(`Monitor off success`);
425} catch (error) {
426  console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
427}
428```
429
430## inputMonitor.on('threeFingersSwipe')<sup>10+</sup>
431
432on(type: 'threeFingersSwipe', receiver: Callback&lt;[ThreeFingersSwipe](js-apis-multimodalinput-gestureevent.md#threefingersswipe)&gt;): void
433
434监听全局触控板的三指滑动事件。
435
436**需要权限:** ohos.permission.INPUT_MONITORING
437
438**系统能力:** SystemCapability.MultimodalInput.Input.InputMonitor
439
440**参数:**
441
442| 参数名       | 类型                         | 必填   | 说明                  |
443| -------- | -------------------------- | ---- | ------------------- |
444| type     | string                     | 是    | 输入设备事件类型,取值'threeFingersSwipe'。 |
445| receiver | Callback&lt;[ThreeFingersSwipe](js-apis-multimodalinput-gestureevent.md#threefingersswipe)&gt; | 是    | 回调函数,异步上报三指滑动输入事件。  |
446
447**错误码**:
448
449以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
450
451| 错误码ID  | 错误信息             |
452| ---- | --------------------- |
453| 201  | Permission denied.   |
454| 202  | SystemAPI permission error.  |
455| 401  | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
456
457**示例:**
458
459```js
460try {
461  inputMonitor.on('threeFingersSwipe', (threeFingersSwipe) => {
462    console.log(`Monitor on success ${JSON.stringify(threeFingersSwipe)}`);
463    return false;
464  });
465} catch (error) {
466  console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
467}
468```
469
470## inputMonitor.off('threeFingersSwipe')<sup>10+</sup>
471
472off(type: 'threeFingersSwipe', receiver?: Callback&lt;[ThreeFingersSwipe](js-apis-multimodalinput-gestureevent.md#threefingersswipe)&gt;): void
473
474取消监听全局触控板的三指滑动事件。
475
476**需要权限:** ohos.permission.INPUT_MONITORING
477
478**系统能力:** SystemCapability.MultimodalInput.Input.InputMonitor
479
480**参数:**
481
482| 参数名       | 类型                         | 必填   | 说明                  |
483| -------- | -------------------------- | ---- | ------------------- |
484| type     | string                     | 是    | 输入设备事件类型,取值'threeFingersSwipe'。 |
485| receiver | Callback&lt;[ThreeFingersSwipe](js-apis-multimodalinput-gestureevent.md#threefingersswipe)&gt; | 否    | 需要取消监听的回调函数。若不填,则取消当前应用监听的所有回调函数。 |
486
487**错误码**:
488
489以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
490
491| 错误码ID  | 错误信息             |
492| ---- | --------------------- |
493| 201  | Permission denied.   |
494| 202  | SystemAPI permission error.  |
495| 401  | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
496
497**示例:**
498
499```js
500// 取消监听单个回调函数
501import { ThreeFingersSwipe } from '@kit.InputKit';
502
503let callback = (threeFingersSwipe: ThreeFingersSwipe) => {
504  console.log(`Monitor on success ${JSON.stringify(threeFingersSwipe)}`);
505  return false;
506};
507try {
508  inputMonitor.on('threeFingersSwipe', callback);
509  inputMonitor.off("threeFingersSwipe", callback);
510  console.log(`Monitor off success`);
511} catch (error) {
512  console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
513}
514```
515
516```js
517// 取消监听所有回调函数
518import { ThreeFingersSwipe } from '@kit.InputKit';
519
520let callback = (threeFingersSwipe: ThreeFingersSwipe) => {
521  console.log(`Monitor on success ${JSON.stringify(threeFingersSwipe)}`);
522  return false;
523};
524try {
525  inputMonitor.on("threeFingersSwipe", callback);
526  inputMonitor.off("threeFingersSwipe");
527  console.log(`Monitor off success`);
528} catch (error) {
529  console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
530}
531```
532
533## inputMonitor.on('fourFingersSwipe')<sup>10+</sup>
534
535on(type: 'fourFingersSwipe', receiver: Callback&lt;[FourFingersSwipe](js-apis-multimodalinput-gestureevent.md#fourfingersswipe)&gt;): void
536
537监听全局触控板的四指滑动事件。
538
539**需要权限:** ohos.permission.INPUT_MONITORING
540
541**系统能力:** SystemCapability.MultimodalInput.Input.InputMonitor
542
543**参数:**
544
545| 参数名       | 类型                         | 必填   | 说明                  |
546| -------- | -------------------------- | ---- | ------------------- |
547| type     | string                     | 是    | 输入设备事件类型,取值'fourFingersSwipe'。 |
548| receiver | Callback&lt;[FourFingersSwipe](js-apis-multimodalinput-gestureevent.md#fourfingersswipe)&gt; | 是    | 回调函数,异步上报四指滑动输入事件。  |
549
550**错误码**:
551
552以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
553
554| 错误码ID  | 错误信息             |
555| ---- | --------------------- |
556| 201  | Permission denied.   |
557| 202  | SystemAPI permission error.  |
558| 401  | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
559
560**示例:**
561
562```js
563try {
564  inputMonitor.on('fourFingersSwipe', (fourFingersSwipe) => {
565    console.log(`Monitor on success ${JSON.stringify(fourFingersSwipe)}`);
566    return false;
567  });
568} catch (error) {
569  console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
570}
571```
572
573## inputMonitor.off('fourFingersSwipe')<sup>10+</sup>
574
575off(type: 'fourFingersSwipe', receiver?: Callback&lt;[FourFingersSwipe](js-apis-multimodalinput-gestureevent.md#fourfingersswipe)&gt;): void
576
577取消监听全局触控板的四指滑动事件。
578
579**需要权限:** ohos.permission.INPUT_MONITORING
580
581**系统能力:** SystemCapability.MultimodalInput.Input.InputMonitor
582
583**参数:**
584
585| 参数名       | 类型                         | 必填   | 说明                  |
586| -------- | -------------------------- | ---- | ------------------- |
587| type     | string                     | 是    | 输入设备事件类型,取值'fourFingersSwipe'。 |
588| receiver | Callback&lt;[FourFingersSwipe](js-apis-multimodalinput-gestureevent.md#fourfingersswipe)&gt; | 否    | 需要取消监听的回调函数。若不填,则取消当前应用监听的所有回调函数。 |
589
590**错误码**:
591
592以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
593
594| 错误码ID  | 错误信息             |
595| ---- | --------------------- |
596| 201  | Permission denied.   |
597| 202  | SystemAPI permission error.  |
598| 401  | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
599
600**示例:**
601
602```js
603// 取消监听单个回调函数
604import { FourFingersSwipe } from '@kit.InputKit';
605
606let callback = (fourFingersSwipe: FourFingersSwipe) => {
607  console.log(`Monitor on success ${JSON.stringify(fourFingersSwipe)}`);
608  return false;
609};
610try {
611  inputMonitor.on('fourFingersSwipe', callback);
612  inputMonitor.off('fourFingersSwipe', callback);
613  console.log(`Monitor off success`);
614} catch (error) {
615  console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
616}
617```
618
619```js
620// 取消监听所有回调函数
621import { FourFingersSwipe } from '@kit.InputKit';
622
623let callback = (fourFingersSwipe: FourFingersSwipe) => {
624  console.log(`Monitor on success ${JSON.stringify(fourFingersSwipe)}`);
625  return false;
626};
627try {
628  inputMonitor.on('fourFingersSwipe', callback);
629  inputMonitor.off('fourFingersSwipe');
630  console.log(`Monitor off success`);
631} catch (error) {
632  console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
633}
634```
635
636## inputMonitor.on('rotate')<sup>11+</sup>
637
638on(type: 'rotate', fingers: number, receiver: Callback&lt;Rotate&gt;): void
639
640监听全局触控板的旋转事件。
641
642**需要权限:** ohos.permission.INPUT_MONITORING
643
644**系统能力:** SystemCapability.MultimodalInput.Input.InputMonitor
645
646**参数:**
647
648| 参数名       | 类型                         | 必填   | 说明                  |
649| -------- | -------------------------- | ---- | ------------------- |
650| type     | string                     | 是    | 输入设备事件类型,取值'rotate'。 |
651| fingers     | number                     | 是    | 旋转的手指数,目前支持监听手指数是2。 |
652| receiver | Callback&lt;[Rotate](js-apis-multimodalinput-gestureevent.md#rotate)&gt; | 是    | 回调函数,异步上报旋转输入事件。  |
653
654**错误码**:
655
656以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
657
658| 错误码ID  | 错误信息             |
659| ---- | --------------------- |
660| 201  | Permission denied.   |
661| 202  | SystemAPI permission error.  |
662| 401  | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
663
664**示例:**
665
666```js
667import type { Rotate } from '@kit.InputKit';
668try {
669  inputMonitor.on('rotate', 2, (rotateEvent: Rotate) => {
670    console.log(`Monitor on success ${JSON.stringify(rotateEvent)}`);
671    return false;
672  });
673} catch (error) {
674  console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
675}
676```
677
678## inputMonitor.off('rotate')<sup>11+</sup>
679
680off(type: 'rotate', fingers: number, receiver?: Callback&lt;Rotate&gt;): void
681
682取消监听全局触控板的旋转事件。
683
684**需要权限:** ohos.permission.INPUT_MONITORING
685
686**系统能力:** SystemCapability.MultimodalInput.Input.InputMonitor
687
688**参数:**
689
690| 参数名       | 类型                         | 必填   | 说明                  |
691| -------- | -------------------------- | ---- | ------------------- |
692| type     | string                     | 是    | 输入设备事件类型,取值'rotate'。 |
693| fingers     | number                     | 是    | 旋转的手指数,目前支持监听手指数是2。 |
694| receiver | Callback&lt;[Rotate](js-apis-multimodalinput-gestureevent.md#rotate)&gt; | 否    | 需要取消监听的回调函数。若不填,则取消当前应用监听的所有回调函数。 |
695
696**错误码**:
697
698以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
699
700| 错误码ID  | 错误信息             |
701| ---- | --------------------- |
702| 201  | Permission denied.   |
703| 202  | SystemAPI permission error.  |
704| 401  | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
705
706**示例:**
707
708```js
709// 取消监听单个回调函数
710import { Rotate } from '@kit.InputKit';
711
712let callback = (rotateEvent: Rotate) => {
713  console.log(`Monitor on success ${JSON.stringify(rotateEvent)}`);
714  return false;
715};
716try {
717  inputMonitor.on('rotate', 2, callback);
718  inputMonitor.off('rotate', 2, callback);
719  console.log(`Monitor off success`);
720} catch (error) {
721  console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
722}
723```
724
725```js
726// 取消监听所有回调函数
727import { Rotate } from '@kit.InputKit';
728
729let callback = (rotateEvent: Rotate) => {
730  console.log(`Monitor on success ${JSON.stringify(rotateEvent)}`);
731  return false;
732};
733try {
734  inputMonitor.on('rotate', 2, callback);
735  inputMonitor.off('rotate', 2);
736  console.log(`Monitor off success`);
737} catch (error) {
738  console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
739}
740```
741
742## inputMonitor.on('pinch')<sup>11+</sup>
743
744on(type: 'pinch', fingers: number, receiver: Callback&lt;Pinch&gt;): void
745
746监听全局触控板的捏合事件。
747
748**需要权限:** ohos.permission.INPUT_MONITORING
749
750**系统能力:** SystemCapability.MultimodalInput.Input.InputMonitor
751
752**参数:**
753
754| 参数名       | 类型                         | 必填   | 说明                  |
755| -------- | -------------------------- | ---- | ------------------- |
756| type     | string                     | 是    | 输入设备事件类型,取值'pinch'。 |
757| fingers     | number                     | 是    | 捏合的手指数,取值范围:大于等于2。 |
758| receiver | Callback&lt;[Pinch](js-apis-multimodalinput-gestureevent.md#pinch)&gt; | 是    | 回调函数,异步上报捏合输入事件。  |
759
760**错误码**:
761
762以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
763
764| 错误码ID  | 错误信息             |
765| ---- | --------------------- |
766| 201  | Permission denied.   |
767| 202  | SystemAPI permission error.  |
768| 401  | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
769
770**示例:**
771
772```js
773import type { Pinch } from '@kit.InputKit';
774try {
775  inputMonitor.on('pinch', 2, (pinchEvent: Pinch) => {
776    console.log(`Monitor on success ${JSON.stringify(pinchEvent)}`);
777    return false;
778  });
779} catch (error) {
780  console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
781}
782```
783
784## inputMonitor.off('pinch')<sup>11+</sup>
785
786off(type: 'pinch', fingers: number, receiver?: Callback&lt;Pinch&gt;): void
787
788取消监听全局触控板的捏合事件。
789
790**需要权限:** ohos.permission.INPUT_MONITORING
791
792**系统能力:** SystemCapability.MultimodalInput.Input.InputMonitor
793
794**参数:**
795
796| 参数名       | 类型                         | 必填   | 说明                  |
797| -------- | -------------------------- | ---- | ------------------- |
798| type     | string                     | 是    | 输入设备事件类型,取值'pinch'。 |
799| fingers     | number                     | 是    | 捏合的手指数,取值范围:大于等于2。 |
800| receiver | Callback&lt;[Pinch](js-apis-multimodalinput-gestureevent.md#pinch)&gt; | 否    | 需要取消监听的回调函数。若不填,则取消当前应用监听的所有回调函数。 |
801
802**错误码**:
803
804以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
805
806| 错误码ID  | 错误信息             |
807| ---- | --------------------- |
808| 201  | Permission denied.   |
809| 202  | SystemAPI permission error.  |
810| 401  | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
811
812**示例:**
813
814```js
815// 取消监听单个回调函数
816import { Pinch } from '@kit.InputKit';
817
818let callback = (pinchEvent: Pinch) => {
819  console.log(`Monitor on success ${JSON.stringify(pinchEvent)}`);
820  return false;
821};
822try {
823  inputMonitor.on('pinch', 2, callback);
824  inputMonitor.off('pinch', 2, callback);
825  console.log(`Monitor off success`);
826} catch (error) {
827  console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
828}
829```
830
831```js
832// 取消监听所有回调函数
833import { Pinch } from '@kit.InputKit';
834
835let callback = (pinchEvent: Pinch) => {
836  console.log(`Monitor on success ${JSON.stringify(pinchEvent)}`);
837  return false;
838};
839try {
840  inputMonitor.on('pinch', 2, callback);
841  inputMonitor.off('pinch', 2);
842  console.log(`Monitor off success`);
843} catch (error) {
844  console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
845}
846```
847
848## inputMonitor.on('threeFingersTap')<sup>11+</sup>
849
850on(type: 'threeFingersTap', receiver: Callback&lt;[ThreeFingersTap](js-apis-multimodalinput-gestureevent.md#threefingerstap)&gt;): void
851
852监听全局触控板的三指轻点事件。
853
854**需要权限:** ohos.permission.INPUT_MONITORING
855
856**系统能力:** SystemCapability.MultimodalInput.Input.InputMonitor
857
858**参数:**
859
860| 参数名   | 类型                                                         | 必填 | 说明                                      |
861| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------- |
862| type     | string                                                       | 是   | 输入设备事件类型,取值'threeFingersTap'。 |
863| receiver | Callback&lt;[ThreeFingersTap](js-apis-multimodalinput-gestureevent.md#threefingerstap)&gt; | 是   | 回调函数,异步上报三指轻点输入事件。      |
864
865**错误码**:
866
867以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
868
869| 错误码ID  | 错误信息             |
870| ---- | --------------------- |
871| 201  | Permission denied.   |
872| 202  | SystemAPI permission error.  |
873| 401  | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
874
875**示例:**
876
877```js
878try {
879  inputMonitor.on('threeFingersTap', (threeFingersTap) => {
880    console.log(`Monitor on success ${JSON.stringify(threeFingersTap)}`);
881    return false;
882  });
883} catch (error) {
884  console.log(`Monitor on failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
885}
886```
887
888## inputMonitor.off('threeFingersTap')<sup>11+</sup>
889
890off(type: 'threeFingersTap', receiver?: Callback&lt;[ThreeFingersTap](js-apis-multimodalinput-gestureevent.md#threefingerstap)&gt;): void
891
892取消监听全局触控板的三指轻点事件。
893
894**需要权限:** ohos.permission.INPUT_MONITORING
895
896**系统能力:** SystemCapability.MultimodalInput.Input.InputMonitor
897
898**参数:**
899
900| 参数名   | 类型                                                         | 必填 | 说明                                                         |
901| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
902| type     | string                                                       | 是   | 输入设备事件类型,取值'threeFingersTap'。                    |
903| receiver | Callback&lt;[ThreeFingersTap](js-apis-multimodalinput-gestureevent.md#threefingerstap)&gt; | 否   | 需要取消监听的回调函数。若不填,则取消当前应用监听的所有回调函数。 |
904
905**错误码**:
906
907以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
908
909| 错误码ID  | 错误信息             |
910| ---- | --------------------- |
911| 201  | Permission denied.   |
912| 202  | SystemAPI permission error.  |
913| 401  | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
914
915**示例:**
916
917```js
918// 取消监听单个回调函数
919import { ThreeFingersTap } from '@kit.InputKit';
920
921let callback = (threeFingersTap: ThreeFingersTap) => {
922  console.log(`Monitor on success ${JSON.stringify(threeFingersTap)}`);
923  return false;
924};
925try {
926  inputMonitor.on('threeFingersTap', callback);
927  inputMonitor.off("threeFingersTap", callback);
928  console.log(`Monitor off success`);
929} catch (error) {
930  console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
931}
932```
933
934```js
935// 取消监听所有回调函数
936import { ThreeFingersTap } from '@kit.InputKit';
937
938let callback = (threeFingersTap: ThreeFingersTap) => {
939  console.log(`Monitor on success ${JSON.stringify(threeFingersTap)}`);
940  return false;
941};
942try {
943  inputMonitor.on('threeFingersTap', callback);
944  inputMonitor.off("threeFingersTap");
945  console.log(`Monitor off success`);
946} catch (error) {
947  console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
948}
949```
950
951## inputMonitor.on('touchscreenSwipe')<sup>14+</sup>
952
953on(type: 'touchscreenSwipe', fingers: number, receiver: Callback&lt;TouchGestureEvent&gt;): void
954
955监听触摸屏滑动手势事件。
956
957**需要权限:** ohos.permission.INPUT_MONITORING
958
959**系统能力:** SystemCapability.MultimodalInput.Input.InputMonitor
960
961**参数:**
962
963| 参数名   | 类型                                                         | 必填 | 说明                                                         |
964| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
965| type     | string                                                       | 是   | 输入设备事件类型,取值'touchscreenSwipe'。                    |
966| fingers  | number                                                       | 是   | 滑动手势的手指数,取值范围:[3,5]。 |
967| receiver | Callback&lt;[TouchGestureEvent](js-apis-multimodalinput-gestureevent-sys.md#touchgestureevent)&gt; | 是   | 回调函数,异步上报触摸屏滑动手势事件。 |
968
969**错误码**:
970
971以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
972
973| 错误码ID  | 错误信息             |
974| ---- | --------------------- |
975| 201  | Permission denied.   |
976| 202  | SystemAPI permission error.  |
977| 401  | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
978
979**示例:**
980
981```js
982import inputMonitor from '@ohos.multimodalInput.inputMonitor';
983import { TouchGestureEvent } from '@ohos.multimodalInput.gestureEvent';
984
985let fingers: number = 4;
986try {
987  inputMonitor.on('touchscreenSwipe', fingers, (event: TouchGestureEvent) => {
988    console.log(`Monitor on success ${JSON.stringify(event)}`);
989  });
990} catch (error) {
991  console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
992}
993```
994
995## inputMonitor.off('touchscreenSwipe')<sup>14+</sup>
996
997off(type: 'touchscreenSwipe', fingers: number, receiver?: Callback&lt;TouchGestureEvent&gt;): void
998
999取消监听触摸屏滑动手势事件。
1000
1001**需要权限:** ohos.permission.INPUT_MONITORING
1002
1003**系统能力:** SystemCapability.MultimodalInput.Input.InputMonitor
1004
1005**参数:**
1006
1007| 参数名   | 类型                                                         | 必填 | 说明                                                         |
1008| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1009| type     | string                                                       | 是   | 输入设备事件类型,取值'touchscreenSwipe'。                    |
1010| fingers  | number                                                       | 是   | 滑动手势的手指数,取值范围:[3,5]。 |
1011| receiver | Callback&lt;[TouchGestureEvent](js-apis-multimodalinput-gestureevent-sys.md#touchgestureevent)&gt; | 否   | 需要取消监听的回调函数。若不填,则取消当前应用监听的所有回调函数。 |
1012
1013**错误码**:
1014
1015以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1016
1017| 错误码ID  | 错误信息             |
1018| ---- | --------------------- |
1019| 201  | Permission denied.   |
1020| 202  | SystemAPI permission error.  |
1021| 401  | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
1022
1023**示例:**
1024
1025```js
1026// 取消监听单个回调函数
1027import inputMonitor from '@ohos.multimodalInput.inputMonitor';
1028import { TouchGestureEvent } from '@ohos.multimodalInput.gestureEvent';
1029
1030let callback = (event: TouchGestureEvent) => {
1031  console.log(`Monitor on success ${JSON.stringify(event)}`);
1032};
1033let fingers: number = 4;
1034try {
1035  inputMonitor.on('touchscreenSwipe', fingers, callback);
1036  inputMonitor.off('touchscreenSwipe', fingers, callback);
1037} catch (error) {
1038  console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1039}
1040```
1041
1042```js
1043// 取消监听所有回调函数
1044import inputMonitor from '@ohos.multimodalInput.inputMonitor';
1045import { TouchGestureEvent } from '@ohos.multimodalInput.gestureEvent';
1046
1047let fingers: number = 4;
1048try {
1049  inputMonitor.on('touchscreenSwipe', fingers, (event: TouchGestureEvent) => {
1050    console.log(`Monitor on success ${JSON.stringify(event)}`);
1051  });
1052  inputMonitor.off('touchscreenSwipe', fingers);
1053} catch (error) {
1054  console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1055}
1056```
1057
1058## inputMonitor.on('touchscreenPinch')<sup>14+</sup>
1059
1060on(type: 'touchscreenPinch', fingers: number, receiver: Callback&lt;TouchGestureEvent&gt;): void
1061
1062监听触摸屏捏合手势事件。
1063
1064**需要权限:** ohos.permission.INPUT_MONITORING
1065
1066**系统能力:** SystemCapability.MultimodalInput.Input.InputMonitor
1067
1068**参数:**
1069
1070| 参数名   | 类型                                                         | 必填 | 说明                                                         |
1071| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1072| type     | string                                                       | 是   | 输入设备事件类型,取值'touchscreenPinch'。                    |
1073| fingers  | number                                                       | 是   | 捏合手势的手指数,取值范围:[4,5]。 |
1074| receiver | Callback&lt;[TouchGestureEvent](js-apis-multimodalinput-gestureevent-sys.md#touchgestureevent)&gt; | 是   | 回调函数,异步上报触摸屏捏合手势事件。 |
1075
1076**错误码**:
1077
1078以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1079
1080| 错误码ID  | 错误信息             |
1081| ---- | --------------------- |
1082| 201  | Permission denied.   |
1083| 202  | SystemAPI permission error.  |
1084| 401  | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
1085
1086**示例:**
1087
1088```js
1089import inputMonitor from '@ohos.multimodalInput.inputMonitor';
1090import { TouchGestureEvent } from '@ohos.multimodalInput.gestureEvent';
1091
1092let fingers: number = 4;
1093try {
1094  inputMonitor.on('touchscreenPinch', fingers, (event: TouchGestureEvent) => {
1095    console.log(`Monitor on success ${JSON.stringify(event)}`);
1096  });
1097} catch (error) {
1098  console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1099}
1100```
1101
1102## inputMonitor.off('touchscreenPinch')<sup>14+</sup>
1103
1104off(type: 'touchscreenPinch', fingers: number, receiver?: Callback&lt;TouchGestureEvent&gt;): void
1105
1106取消监听触摸屏捏合手势事件。
1107
1108**需要权限:** ohos.permission.INPUT_MONITORING
1109
1110**系统能力:** SystemCapability.MultimodalInput.Input.InputMonitor
1111
1112**参数:**
1113
1114| 参数名   | 类型                                                         | 必填 | 说明                                                         |
1115| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1116| type     | string                                                       | 是   | 输入设备事件类型,取值'touchscreenPinch'。                    |
1117| fingers  | number                                                       | 是   | 捏合手势的手指数,取值范围:[4,5]。 |
1118| receiver | Callback&lt;[TouchGestureEvent](js-apis-multimodalinput-gestureevent-sys.md#touchgestureevent)&gt; | 否   | 需要取消监听的回调函数。若不填,则取消当前应用监听的所有回调函数。 |
1119
1120**错误码**:
1121
1122以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1123
1124| 错误码ID  | 错误信息             |
1125| ---- | --------------------- |
1126| 201  | Permission denied.   |
1127| 202  | SystemAPI permission error.  |
1128| 401  | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
1129
1130**示例:**
1131
1132```js
1133// 取消监听单个回调函数
1134import inputMonitor from '@ohos.multimodalInput.inputMonitor';
1135import { TouchGestureEvent } from '@ohos.multimodalInput.gestureEvent';
1136
1137let callback = (event: TouchGestureEvent) => {
1138  console.log(`Monitor on success ${JSON.stringify(event)}`);
1139};
1140let fingers: number = 4;
1141try {
1142  inputMonitor.on('touchscreenPinch', fingers, callback);
1143  inputMonitor.off("touchscreenPinch", fingers, callback);
1144} catch (error) {
1145  console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1146}
1147```
1148
1149```js
1150// 取消监听所有回调函数
1151import inputMonitor from '@ohos.multimodalInput.inputMonitor';
1152import { TouchGestureEvent } from '@ohos.multimodalInput.gestureEvent';
1153
1154let fingers: number = 4;
1155try {
1156  inputMonitor.on('touchscreenPinch', fingers, (event: TouchGestureEvent) => {
1157    console.log(`Monitor on success ${JSON.stringify(event)}`);
1158  });
1159  inputMonitor.off("touchscreenPinch", fingers);
1160} catch (error) {
1161  console.log(`Monitor execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1162}
1163```
1164