• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.cooperate (Screen Hopping) (System API)
2
3The **cooperate** module implements screen hopping for two or more networked devices to share the keyboard and mouse for collaborative operations.
4
5> **NOTE**
6>
7> - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8>
9> - The APIs provided by this module are system APIs.
10
11## Modules to Import
12
13```ts
14import cooperate from '@ohos.cooperate';
15```
16
17## cooperate.prepareCooperate<sup>11+</sup>
18
19prepareCooperate(callback: AsyncCallback&lt;void&gt;): void;
20
21Prepares for screen hopping. This API uses an asynchronous callback to return the result.
22
23**Required permissions**: ohos.permission.COOPERATE_MANAGER
24
25**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
26
27**Parameters**
28
29| Name  | Type                     | Mandatory| Description                                                        |
30| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
31| callback | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the operation result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
32
33**Error codes**
34
35For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
36
37| ID| Error Message         |
38| -------- | ----------------- |
39| 201 | Permission denied. |
40| 202 | Not system application. |
41| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
42
43**Example**
44
45```ts
46import { BusinessError } from '@ohos.base';
47try {
48  cooperate.prepareCooperate((error: BusinessError) => {
49    if (error) {
50      console.log(`Keyboard mouse crossing prepareCooperate failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
51      return;
52    }
53    console.log(`Keyboard mouse crossing prepareCooperate success.`);
54  });
55} catch (error) {
56  console.log(`Keyboard mouse crossing prepareCooperate failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
57}
58```
59
60## cooperate.prepareCooperate<sup>11+</sup>
61
62prepareCooperate(): Promise&lt;void&gt;;
63
64Prepares for screen hopping. This API uses a promise to return the result.
65
66**Required permissions**: ohos.permission.COOPERATE_MANAGER
67
68**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
69
70**Return value**
71
72| Parameters               | Description                     |
73| ------------------- | ------------------------- |
74| Promise&lt;void&gt; | Promise that returns no value.|
75
76**Error codes**
77
78For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
79
80| ID| Error Message         |
81| -------- | ----------------- |
82| 201 | Permission denied. |
83| 202 | Not system application. |
84| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
85
86**Example**
87
88```ts
89import { BusinessError } from '@ohos.base';
90try {
91  cooperate.prepareCooperate().then(() => {
92    console.log(`Keyboard mouse crossing prepareCooperate success.`);
93  }, (error: BusinessError) => {
94    console.log(`Keyboard mouse crossing prepareCooperate failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
95  });
96} catch (error) {
97  console.log(`Keyboard mouse crossing prepareCooperate failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
98}
99```
100
101
102
103## cooperate.unprepareCooperate<sup>11+</sup>
104
105unprepareCooperate(callback: AsyncCallback&lt;void&gt;): void;
106
107Cancels the preparation for screen hopping. This API uses an asynchronous callback to return the result.
108
109**Required permissions**: ohos.permission.COOPERATE_MANAGER
110
111**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
112
113| Name  | Type                     | Mandatory| Description                                                        |
114| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
115| callback | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the operation result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
116
117**Error codes**
118
119For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
120
121| ID| Error Message         |
122| -------- | ----------------- |
123| 201 | Permission denied. |
124| 202 | Not system application. |
125| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
126
127**Example**
128
129```ts
130import { BusinessError } from '@ohos.base';
131try {
132  cooperate.unprepareCooperate((error: BusinessError) => {
133    if (error) {
134      console.log(`Keyboard mouse crossing unprepareCooperate failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
135      return;
136    }
137    console.log(`Keyboard mouse crossing unprepareCooperate success.`);
138  });
139} catch (error) {
140  console.log(`Keyboard mouse crossing unprepareCooperate failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
141}
142```
143
144## cooperate.unprepareCooperate<sup>11+</sup>
145
146unprepareCooperate(): Promise&lt;void&gt;;
147
148Cancels the preparation for screen hopping. This API uses a promise to return the result.
149
150**Required permissions**: ohos.permission.COOPERATE_MANAGER
151
152**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
153
154**Return value**
155
156| Parameters               | Description                     |
157| ------------------- | ------------------------- |
158| Promise&lt;void&gt; | Promise that returns no value.|
159
160**Error codes**
161
162For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
163
164| ID| Error Message         |
165| -------- | ----------------- |
166| 201 | Permission denied. |
167| 202 | Not system application. |
168
169**Example**
170
171```ts
172import { BusinessError } from '@ohos.base';
173try {
174  cooperate.unprepareCooperate().then(() => {
175    console.log(`Keyboard mouse crossing unprepareCooperate success.`);
176  }, (error: BusinessError) => {
177    console.log(`Keyboard mouse crossing unprepareCooperate failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
178  });
179} catch (error) {
180  console.log(`Keyboard mouse crossing unprepareCooperate failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
181}
182```
183
184
185
186## cooperate.activateCooperate<sup>11+</sup>
187
188activateCooperate(targetNetworkId: string, inputDeviceId: number, callback: AsyncCallback&lt;void&gt;): void;
189
190Starts screen hopping. This API uses an asynchronous callback to return the result.
191
192**Required permissions**: ohos.permission.COOPERATE_MANAGER
193
194**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
195
196**Parameters**
197
198| Name         | Type                     | Mandatory| Description                                                        |
199| --------------- | ------------------------- | ---- | ------------------------------------------------------------ |
200| targetNetworkId | string                    | Yes  | Descriptor of the target device for screen hopping.                                    |
201| inputDeviceId   | number                    | Yes  | Identifier of the input device for screen hopping.                                      |
202| callback        | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the operation result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
203
204**Error codes**
205
206For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
207
208| ID| Error Message         |
209| -------- | ----------------- |
210| 201 | Permission denied. |
211| 202 | Not system application. |
212| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
213| 20900001 | Service exception. Possible causes: 1. A system error, such as null pointer, container-related exception, or IPC exception. 2. N-API invocation exception or invalid N-API status. |
214
215**Example**
216
217```ts
218import { BusinessError } from '@ohos.base';
219let targetNetworkId = "networkId";
220let inputDeviceId = 0;
221try {
222  cooperate.activateCooperate(targetNetworkId, inputDeviceId, (error: BusinessError) => {
223    if (error) {
224      console.log(`Start Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
225      return;
226    }
227    console.log(`Start Keyboard mouse crossing success.`);
228  });
229} catch (error) {
230  console.log(`Start Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
231}
232```
233
234## cooperate.activateCooperate<sup>11+</sup>
235
236activateCooperate(targetNetworkId: string, inputDeviceId: number): Promise&lt;void&gt;;
237
238Starts screen hopping. This API uses a promise to return the result.
239
240**Required permissions**: ohos.permission.COOPERATE_MANAGER
241
242**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
243
244**Parameters**
245
246| Name         | Type  | Mandatory| Description                    |
247| --------------- | ------ | ---- | ------------------------ |
248| targetNetworkId | string | Yes  | Descriptor of the target device for screen hopping.|
249| inputDeviceId   | number | Yes  | Identifier of the input device for screen hopping.  |
250
251**Return value**
252
253| Name             | Description                     |
254| ------------------- | ------------------------- |
255| Promise&lt;void&gt; | Promise that returns no value.|
256
257**Error codes**
258
259For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
260
261| ID| Error Message         |
262| -------- | ----------------- |
263| 201 | Permission denied. |
264| 202 | Not system application. |
265| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
266| 20900001 | Service exception. Possible causes: 1. A system error, such as null pointer, container-related exception, or IPC exception. 2. N-API invocation exception or invalid N-API status. |
267
268**Example**
269
270```ts
271import { BusinessError } from '@ohos.base';
272let targetNetworkId = "networkId";
273let inputDeviceId = 0;
274try {
275 cooperate.activateCooperate(targetNetworkId, inputDeviceId).then(() => {
276    console.log(`Start Keyboard mouse crossing success.`);
277  }, (error: BusinessError) => {
278    console.log(`Start Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
279  });
280} catch (error) {
281  console.log(`Start Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
282}
283```
284
285
286
287## cooperate.deactivateCooperate<sup>11+</sup>
288
289deactivateCooperate(isUnchained: boolean, callback: AsyncCallback&lt;void&gt;): void;
290
291Stops screen hopping. This API uses an asynchronous callback to return the result.
292
293**Required permissions**: ohos.permission.COOPERATE_MANAGER
294
295**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
296
297**Parameters**
298
299| Name     | Type                     | Mandatory| Description                                                        |
300| ----------- | ------------------------- | ---- | ------------------------------------------------------------ |
301| isUnchained | boolean                   | Yes  | Whether to disable the cross-device link. The value **true** means to disable the cross-device link, and the value **false** means the opposite.|
302| callback    | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the operation result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
303
304**Error codes**
305
306For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
307
308| ID| Error Message         |
309| -------- | ----------------- |
310| 201 | Permission denied. |
311| 202 | Not system application. |
312| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
313
314**Example**
315
316```ts
317import { BusinessError } from '@ohos.base';
318try {
319  cooperate.deactivateCooperate(false, (error: BusinessError) => {
320    if (error) {
321      console.log(`Stop Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
322      return;
323    }
324    console.log(`Stop Keyboard mouse crossing success.`);
325  });
326} catch (error) {
327  console.log(`Stop Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
328}
329```
330
331## cooperate.deactivateCooperate<sup>11+</sup>
332
333deactivateCooperate(isUnchained: boolean): Promise&lt;void&gt;;
334
335Stops screen hopping. This API uses a promise to return the result.
336
337**Required permissions**: ohos.permission.COOPERATE_MANAGER
338
339**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
340
341**Parameters**
342
343| Name     | Type   | Mandatory| Description                                                        |
344| ----------- | ------- | ---- | ------------------------------------------------------------ |
345| isUnchained | boolean | Yes  | Whether to disable the cross-device link. The value **true** means to disable the cross-device link, and the value **false** means the opposite.|
346
347**Return value**
348
349| Name             | Description                     |
350| ------------------- | ------------------------- |
351| Promise&lt;void&gt; | Promise that returns no value.|
352
353**Error codes**
354
355For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
356
357| ID| Error Message         |
358| -------- | ----------------- |
359| 201 | Permission denied. |
360| 202 | Not system application. |
361
362**Example**
363
364```ts
365import { BusinessError } from '@ohos.base';
366try {
367  cooperate.deactivateCooperate(false).then(() => {
368    console.log(`Stop Keyboard mouse crossing success.`);
369  }, (error: BusinessError) => {
370    console.log(`Stop Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
371  });
372} catch (error) {
373  console.log(`Stop Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
374}
375```
376
377
378
379## cooperate.getCooperateSwitchState<sup>11+</sup>
380
381getCooperateSwitchState(networkId: string, callback: AsyncCallback&lt;boolean&gt;): void;
382
383Obtains the screen hopping status of the target device. This API uses an asynchronous callback to return the result.
384
385**Required permissions**: ohos.permission.COOPERATE_MANAGER
386
387**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
388
389**Parameters**
390
391| Name   | Type                        | Mandatory| Description                                                        |
392| --------- | ---------------------------- | ---- | ------------------------------------------------------------ |
393| networkId | string                       | Yes  | Descriptor of the target device for screen hopping.                                    |
394| callback  | AsyncCallback&lt;boolean&gt; | Yes  | Callback used to return the result. The value **true** indicates that screen hopping is enabled, and the value **false** indicates the opposite.|
395
396**Error codes**
397
398For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
399
400| ID| Error Message         |
401| -------- | ----------------- |
402| 201 | Permission denied. |
403| 202 | Not system application. |
404| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
405
406**Example**
407
408```ts
409import { BusinessError } from '@ohos.base';
410let deviceDescriptor = "networkId";
411try {
412  cooperate.getCooperateSwitchState(deviceDescriptor, (error: BusinessError, data: boolean) => {
413    if (error) {
414      console.log(`Get the status failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
415      return;
416    }
417    console.log(`Get the status success, data: ${JSON.stringify(data)}`);
418  });
419} catch (error) {
420  console.log(`Get the status failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
421}
422```
423
424## cooperate.getCooperateSwitchState<sup>11+</sup>
425
426getCooperateSwitchState(networkId: string): Promise&lt;boolean&gt;;
427
428Obtains the screen hopping status of the target device. This API uses a promise to return the result.
429
430**Required permissions**: ohos.permission.COOPERATE_MANAGER
431
432**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
433
434**Parameters**
435
436| Name   | Type  | Mandatory| Description                    |
437| --------- | ------ | ---- | ------------------------ |
438| networkId | string | Yes  | Descriptor of the target device for screen hopping.|
439
440**Return value**
441
442| Parameters                  | Description                                                        |
443| ---------------------- | ------------------------------------------------------------ |
444| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** indicates that screen hopping is enabled, and the value **false** indicates the opposite.|
445
446**Error codes**
447
448For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
449
450| ID| Error Message         |
451| -------- | ----------------- |
452| 201 | Permission denied. |
453| 202 | Not system application. |
454| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
455
456**Example**
457
458```ts
459import { BusinessError } from '@ohos.base';
460let deviceDescriptor = "networkId";
461try {
462  cooperate.getCooperateSwitchState(deviceDescriptor).then((data: boolean) => {
463    console.log(`Get the status success, data: ${JSON.stringify(data)}`);
464  }, (error: BusinessError) => {
465    console.log(`Get the status failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
466  });
467} catch (error) {
468  console.log(`Get the status failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
469}
470```
471
472
473
474## on('cooperateMessage')<sup>11+</sup>
475
476on(type: 'cooperateMessage', callback: Callback&lt;CooperateMessage&gt;): void;
477
478Enables listening for screen hopping status change events.
479
480**Required permissions**: ohos.permission.COOPERATE_MANAGER
481
482**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
483
484**Parameters**
485
486| Name  | Type                                                 | Mandatory| Description                                |
487| -------- | ----------------------------------------------------- | ---- | ------------------------------------ |
488| type     | string                                                | Yes  | Event type. The value is **cooperateMessage**.  |
489| callback | Callback&lt;[CooperateMessage](#cooperatemessage11)&gt; | Yes  | Callback used to return the result.|
490
491**Error codes**
492
493For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
494
495| ID| Error Message         |
496| -------- | ----------------- |
497| 201 | Permission denied. |
498| 202 | Not system application. |
499| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
500
501**Example**
502
503```ts
504function callback(msg: cooperate.CooperateMessage) {
505  console.log(`Keyboard mouse crossing event: ${JSON.stringify(msg)}`);
506  return false;
507}
508try {
509  cooperate.on('cooperateMessage', callback);
510} catch (error) {
511  console.log(`Register failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
512}
513```
514
515
516
517## off('cooperateMessage')<sup>11+</sup>
518
519off(type: 'cooperateMessage', callback?: Callback&lt;CooperateMessage&gt;): void;
520
521Disables listening for screen hopping status change events.
522
523**Required permissions**: ohos.permission.COOPERATE_MANAGER
524
525**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
526
527**Parameters**
528
529| Name  | Type                                                 | Mandatory| Description                                                        |
530| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ |
531| type     | string                                                | Yes  | Event type. The value is **cooperate**.                               |
532| callback | Callback&lt;[CooperateMessage](#cooperatemessage11)&gt; | No  | Callback to be unregistered. If this parameter is not specified, all callbacks registered by the current application will be unregistered.|
533
534**Error codes**
535
536For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
537
538| ID| Error Message         |
539| -------- | ----------------- |
540| 201 | Permission denied. |
541| 202 | Not system application. |
542| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
543
544**Example**
545
546```ts
547// Unregister a single callback.
548function callbackOn(msgOn: cooperate.CooperateMessage) {
549  console.log(`Keyboard mouse crossing event: ${JSON.stringify(msgOn)}`);
550  return false;
551}
552function callbackOff(msgOff: cooperate.CooperateMessage) {
553  console.log(`Keyboard mouse crossing event: ${JSON.stringify(msgOff)}`);
554  return false;
555}
556try {
557  cooperate.on('cooperateMessage', callbackOn);
558  cooperate.off('cooperateMessage', callbackOff);
559} catch (error) {
560  console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
561}
562```
563
564```ts
565// Unregister all callbacks.
566function callbackOn(msg: cooperate.CooperateMessage) {
567  console.log(`Keyboard mouse crossing event: ${JSON.stringify(msg)}`);
568  return false;
569}
570try {
571  cooperate.on('cooperateMessage', callbackOn);
572  cooperate.off('cooperateMessage');
573} catch (error) {
574  console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
575}
576```
577
578
579## on('cooperateMouse')<sup>12+</sup>
580
581on(type: 'cooperateMouse', networkId: string, callback: Callback&lt;MouseLocation&gt;): void;
582
583Registers a listener for the mouse cursor position of a device.
584
585**Required permissions**: ohos.permission.COOPERATE_MANAGER
586
587**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
588
589**Parameters**
590
591| Name  | Type                                                 | Mandatory| Description                                |
592| -------- | ----------------------------------------------------- | ---- | ------------------------------------ |
593| type     | string                                                | Yes  | Event type, which is **'cooperateMouse'**.  |
594| networkId| string                                                | Yes  | Descriptor of the target device.  |
595| callback | Callback&lt;[MouseLocation](#mouselocation12)&gt; | Yes  | Callback used to return the mouse cursor position of the device.|
596
597**Error codes**
598
599For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
600
601| ID| Error Message         |
602| -------- | ----------------- |
603| 201 | Permission denied. |
604| 202 | Not system application. |
605| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
606
607**Example**
608
609```ts
610function callback(data: cooperate.MouseLocation) {
611  console.log('displayX:' + data.displayX + 'displayY:' + data.displayX + 'displayWidth:' +
612    data.displayWidth + 'displayHeight:' + data.displayHeight );
613}
614try {
615  let networkId: string = 'Default';
616  cooperate.on('cooperateMouse', networkId, callback);
617} catch (error) {
618  console.log(`Register failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
619}
620```
621
622
623
624## off('cooperateMouse')<sup>12+</sup>
625
626off(type: 'cooperateMouse', networkId: string, callback?: Callback&lt;MouseLocation&gt;): void;
627
628Unregisters the listener for the mouse cursor position of a device.
629
630**Required permissions**: ohos.permission.COOPERATE_MANAGER
631
632**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
633
634**Parameters**
635
636| Name  | Type                                                 | Mandatory| Description                                                        |
637| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ |
638| type     | string                                                | Yes  | Event type, which is **'cooperateMouse'**.                               |
639| networkId| string                                                | Yes  | Descriptor of the target device.  |
640| callback | Callback&lt;[MouseLocation](#mouselocation12)&gt; | No  | Callback to be unregistered. If this parameter is not specified, all callbacks registered by the current application will be unregistered.|
641
642**Error codes**
643
644For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
645
646| ID| Error Message         |
647| -------- | ----------------- |
648| 201 | Permission denied. |
649| 202 | Not system application. |
650| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
651
652**Example**
653
654```ts
655// Unregister a single callback.
656function callbackOn(data: cooperate.MouseLocation) {
657  console.log('Register mouse location listener');
658  return false;
659}
660function callbackOff(data: cooperate.MouseLocation) {
661  console.log('Unregister mouse location listener');
662  return false;
663}
664try {
665  let networkId: string = 'Default';
666  cooperate.on('cooperateMouse', networkId, callbackOn);
667  cooperate.off('cooperateMouse', networkId, callbackOff);
668} catch (error) {
669  console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
670}
671```
672
673```ts
674// Unregister all callbacks.
675function callbackOn(data: cooperate.MouseLocation) {
676  console.log('Register mouse location listener');
677}
678try {
679  let networkId: string = 'Default';
680  cooperate.on('cooperateMouse', networkId, callbackOn);
681  cooperate.off('cooperateMouse', networkId);
682} catch (error) {
683  console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
684}
685```
686
687
688
689## CooperateMessage<sup>11+</sup>
690
691Defines a screen hopping status change event.
692
693**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
694
695| Name     | Type          | Readable| Writable| Description                    |
696| --------- | -------------- | ---- | ---- | ------------------------ |
697| networkId | string         | Yes  | No  | Descriptor of the target device for screen hopping.|
698| state     | CooperateState | Yes  | No  | Screen hopping status.        |
699
700
701## MouseLocation<sup>12+</sup>
702
703Defines the mouse pointer position for screen hopping.
704
705**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
706
707| Name          | Type           | Readable| Writable| Description                          |
708| ---------      | -------------- | ---- | ---- | ------------------------       |
709| displayX       | number         | Yes  | No  | Position of the mouse pointer on the X coordinate of the screen.|
710| displayY       | number         | Yes  | No  | Position of the mouse pointer on the Y coordinate of the screen.|
711| displayWidth   | number         | Yes  | No  | Screen width, in pixels.                     |
712| displayHeight  | number         | Yes  | No  | Screen height, in pixels.                     |
713
714## CooperateState<sup>11+</sup>
715
716Screen hopping status.
717
718**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
719
720| Name                          | Type   | Readable| Writable| Description                  |
721| ------------------------------ | ------ | ---- | ---- | ---------------------- |
722| COOPERATE_PREPARE              | number | Yes  | No  | The preparation for screen hopping is finished.    |
723| COOPERATE_UNPREPARE            | number | Yes  | No  | The preparation for screen hopping is cancelled.|
724| COOPERATE_ACTIVATE             | number | Yes  | No  | Screen hopping starts.    |
725| COOPERATE_ACTIVATE_SUCCESS     | number | Yes  | No  | Starting screen hopping succeeds.|
726| COOPERATE_ACTIVATE_FAIL        | number | Yes  | No  | Starting screen hopping fails.|
727| COOPERATE_DEACTIVATE_SUCCESS   | number | Yes  | No  | Stopping screen hopping succeeds.|
728| COOPERATE_DEACTIVATE_FAIL      | number | Yes  | No  | Stopping screen hopping fails.|
729| COOPERATE_SESSION_DISCONNECTED | number | Yes  | No  | The screen hopping session is disconnected.|
730| COOPERATE_ACTIVATE_FAILURE     | number | Yes  | No  | Screen hopping fails to start.|
731| COOPERATE_DEACTIVATE_FAILURE   | number | Yes  | No  | Screen hopping fails to stop.|
732
733
734## MouseLocation<sup>12+</sup>
735
736Represents the mouse cursor position.
737
738**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
739
740| Name          | Type          | Readable| Writable| Description                    |
741| ---------     | -------------- | ---- | ---- | ------------------------ |
742| displayX      | number         | Yes  | No  | X coordinate of the mouse cursor.|
743| displayY      | number         | Yes  | No  | Y coordinate of the mouse cursor.|
744| displayWidth  | number         | Yes  | No  | Width of the screen where the mouse cursor is located, in pixels.|
745| displayHeight | number         | Yes  | No  | Height of the screen where the mouse cursor is located, in pixels.|
746
747
748## cooperate.prepare<sup>(deprecated)</sup>
749
750prepare(callback: AsyncCallback&lt;void&gt;): void;
751
752Prepares for screen hopping. This API uses an asynchronous callback to return the result.
753
754> **NOTE**
755>
756> This API is deprecated since API version 10. You are advised to use [cooperate.prepareCooperate](#cooperatepreparecooperate11).
757
758**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
759
760**Parameters**
761
762| Name   | Type     | Mandatory | Description   |
763| -------- | ------------------------- | ---- | --------------------------- |
764| callback | AsyncCallback&lt;void&gt;  | Yes|Callback used to return the operation result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.  |
765
766**Error codes**
767
768For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
769
770| ID| Error Message         |
771| -------- | ----------------- |
772| 202 | Not system application. |
773| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
774
775**Example**
776
777```ts
778import { BusinessError } from '@ohos.base';
779try {
780  cooperate.prepare((error: BusinessError) => {
781    if (error) {
782      console.log(`Keyboard mouse crossing prepare failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
783      return;
784    }
785    console.log(`Keyboard mouse crossing prepare success.`);
786  });
787} catch (error) {
788  console.log(`Keyboard mouse crossing prepare failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
789}
790```
791
792## cooperate.prepare<sup>(deprecated)</sup>
793
794prepare(): Promise&lt;void&gt;;
795
796Prepares for screen hopping. This API uses a promise to return the result.
797
798> **NOTE**
799>
800> This API is deprecated since API version 10. You are advised to use [cooperate.prepareCooperate](#cooperatepreparecooperate11-1).
801
802**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
803
804**Return value**
805
806| Parameters                | Description                    |
807| ------------------- | ------------------------------- |
808| Promise&lt;void&gt;      | Promise that returns no value.|
809
810**Error codes**
811
812For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
813
814| ID| Error Message         |
815| -------- | ----------------- |
816| 202 | Not system application. |
817| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
818
819**Example**
820
821```ts
822import { BusinessError } from '@ohos.base';
823try {
824  cooperate.prepare().then(() => {
825    console.log(`Keyboard mouse crossing prepare success.`);
826  }, (error: BusinessError) => {
827    console.log(`Keyboard mouse crossing prepare failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
828  });
829} catch (error) {
830  console.log(`Keyboard mouse crossing prepare failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
831}
832```
833
834
835
836## cooperate.unprepare<sup>(deprecated)</sup>
837
838unprepare(callback: AsyncCallback&lt;void&gt;): void;
839
840Cancels the preparation for screen hopping. This API uses an asynchronous callback to return the result.
841
842> **NOTE**
843>
844> This API is deprecated since API version 10. You are advised to use [cooperate.unprepareCooperate](#cooperateunpreparecooperate11).
845
846**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
847
848| Name  | Type                     | Mandatory| Description                                      |
849| -------- | ------------------------- | ---- | ------------------------------------------ |
850| callback | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the operation result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
851
852**Error codes**
853
854For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
855
856| ID| Error Message         |
857| -------- | ----------------- |
858| 202 | Not system application. |
859| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
860
861**Example**
862
863```ts
864import { BusinessError } from '@ohos.base';
865try {
866  cooperate.unprepare((error: BusinessError) => {
867    if (error) {
868      console.log(`Keyboard mouse crossing unprepare failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
869      return;
870    }
871    console.log(`Keyboard mouse crossing unprepare success.`);
872  });
873} catch (error) {
874  console.log(`Keyboard mouse crossing unprepare failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
875}
876```
877
878## cooperate.unprepare<sup>(deprecated)</sup>
879
880unprepare(): Promise&lt;void&gt;;
881
882Cancels the preparation for screen hopping. This API uses a promise to return the result.
883
884> **NOTE**
885>
886> This API is deprecated since API version 10. You are advised to use [cooperate.unprepareCooperate](#cooperateunpreparecooperate11-1).
887
888**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
889
890**Return value**
891
892| Parameters               | Description                                         |
893| ------------------- | --------------------------------------------- |
894| Promise&lt;void&gt; | Promise that returns no value.|
895
896**Error codes**
897
898For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
899
900| ID| Error Message         |
901| -------- | ----------------- |
902| 202 | Not system application. |
903| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
904
905**Example**
906
907```ts
908import { BusinessError } from '@ohos.base';
909try {
910  cooperate.unprepare().then(() => {
911    console.log(`Keyboard mouse crossing unprepare success.`);
912  }, (error: BusinessError) => {
913    console.log(`Keyboard mouse crossing unprepare failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
914  });
915} catch (error) {
916  console.log(`Keyboard mouse crossing unprepare failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
917}
918```
919
920
921
922## cooperate.activate<sup>(deprecated)</sup>
923
924activate(targetNetworkId: string, inputDeviceId: number, callback: AsyncCallback&lt;void&gt;): void;
925
926Starts screen hopping. This API uses an asynchronous callback to return the result.
927
928> **NOTE**
929>
930> This API is deprecated since API version 10. You are advised to use [cooperate.activateCooperate](#cooperateactivatecooperate11).
931
932**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
933
934**Parameters**
935
936| Name               | Type                         | Mandatory | Description                           |
937| --------             | ---------------------------- | ----  | ----------------------------   |
938| targetNetworkId | string                       |  Yes  | Descriptor of the target device for screen hopping.            |
939| inputDeviceId | number                       |  Yes  | Identifier of the input device for screen hopping.|
940| callback             | AsyncCallback&lt;void&gt; |  Yes   | Callback used to return the operation result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
941
942**Error codes**
943
944For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
945
946| ID| Error Message|
947| -------- | ---------------------------------------- |
948| 20900001 | Service exception. Possible causes: 1. A system error, such as null pointer, container-related exception, or IPC exception. 2. N-API invocation exception or invalid N-API status. |
949| 202 | Not system application. |
950| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
951
952**Example**
953
954```ts
955import { BusinessError } from '@ohos.base';
956let targetNetworkId = "networkId";
957let inputDeviceId = 0;
958try {
959  cooperate.activate(targetNetworkId, inputDeviceId, (error: BusinessError) => {
960    if (error) {
961      console.log(`Start Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
962      return;
963    }
964    console.log(`Start Keyboard mouse crossing success.`);
965  });
966} catch (error) {
967  console.log(`Start Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
968}
969```
970
971## cooperate.activate<sup>(deprecated)</sup>
972
973activate(targetNetworkId: string, inputDeviceId: number): Promise&lt;void&gt;;
974
975Starts screen hopping. This API uses a promise to return the result.
976
977> **NOTE**
978>
979> This API is deprecated since API version 10. You are advised to use [cooperate.activateCooperate](#cooperateactivatecooperate11-1).
980
981**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
982
983**Parameters**
984
985| Name               | Type                         | Mandatory | Description                           |
986| --------             | ---------------------------- | ----  | ----------------------------   |
987| targetNetworkId | string                       |  Yes  | Descriptor of the target device for screen hopping.            |
988| inputDeviceId | number                       |  Yes  | Identifier of the input device for screen hopping.|
989
990
991
992**Return value**
993
994| Name                 | Description                            |
995| ---------------------- | ------------------------------- |
996| Promise&lt;void&gt; | Promise that returns no value.    |
997
998**Error codes**
999
1000For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
1001
1002| ID| Error Message|
1003| -------- | ---------------------------------------- |
1004| 20900001 | Service exception. Possible causes: 1. A system error, such as null pointer, container-related exception, or IPC exception. 2. N-API invocation exception or invalid N-API status.|
1005| 202 | Not system application. |
1006| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
1007
1008**Example**
1009
1010```ts
1011import { BusinessError } from '@ohos.base';
1012let targetNetworkId = "networkId";
1013let inputDeviceId = 0;
1014try {
1015 cooperate.activate(targetNetworkId, inputDeviceId).then(() => {
1016    console.log(`Start Keyboard mouse crossing success.`);
1017  }, (error: BusinessError) => {
1018    console.log(`Start Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1019  });
1020} catch (error) {
1021  console.log(`Start Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1022}
1023```
1024
1025
1026
1027## cooperate.deactivate<sup>(deprecated)</sup>
1028
1029deactivate(isUnchained: boolean, callback: AsyncCallback&lt;void&gt;): void;
1030
1031Stops screen hopping. This API uses an asynchronous callback to return the result.
1032
1033> **NOTE**
1034>
1035> This API is deprecated since API version 10. You are advised to use [cooperate.deactivateCooperate](#cooperatedeactivatecooperate11).
1036
1037**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
1038
1039**Parameters**
1040
1041| Name               | Type                         | Mandatory | Description                           |
1042| --------             | ---------------------------- | ----  | ----------------------------   |
1043| isUnchained | boolean | Yes| Whether to disable the cross-device link.<br> The value **true** means to disable the cross-device link, and the value **false** means the opposite.|
1044| callback     | AsyncCallback&lt;void&gt; |  Yes  | Callback used to return the operation result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
1045
1046**Error codes**
1047
1048For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
1049
1050| ID| Error Message         |
1051| -------- | ----------------- |
1052| 202 | Not system application. |
1053| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
1054
1055**Example**
1056
1057```ts
1058import { BusinessError } from '@ohos.base';
1059try {
1060  cooperate.deactivate(false, (error: BusinessError) => {
1061    if (error) {
1062      console.log(`Stop Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1063      return;
1064    }
1065    console.log(`Stop Keyboard mouse crossing success.`);
1066  });
1067} catch (error) {
1068  console.log(`Stop Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1069}
1070```
1071
1072## cooperate.deactivate<sup>(deprecated)</sup>
1073
1074deactivate(isUnchained: boolean): Promise&lt;void&gt;;
1075
1076Stops screen hopping. This API uses a promise to return the result.
1077
1078> **NOTE**
1079>
1080> This API is deprecated since API version 10. You are advised to use [cooperate.deactivateCooperate](#cooperatedeactivatecooperate11-1).
1081
1082**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
1083
1084**Parameters**
1085
1086| Name     | Type   | Mandatory| Description              |
1087| ----------- | ------- | ---- | ------------------ |
1088| isUnchained | boolean | Yes  | Whether to disable the cross-device link.<br> The value **true** means to disable the cross-device link, and the value **false** means the opposite.|
1089
1090
1091
1092**Return value**
1093
1094| Name               | Description                           |
1095| --------             | ----------------------------   |
1096| Promise&lt;void&gt; |  Promise that returns no value.     |
1097
1098**Error codes**
1099
1100For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
1101
1102| ID| Error Message         |
1103| -------- | ----------------- |
1104| 202 | Not system application. |
1105
1106**Example**
1107
1108```ts
1109import { BusinessError } from '@ohos.base';
1110try {
1111  cooperate.deactivate(false).then(() => {
1112    console.log(`Stop Keyboard mouse crossing success.`);
1113  }, (error: BusinessError) => {
1114    console.log(`Stop Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1115  });
1116} catch (error) {
1117  console.log(`Stop Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1118}
1119```
1120
1121
1122
1123## cooperate.getCrossingSwitchState<sup>(deprecated)</sup>
1124
1125getCrossingSwitchState(networkId: string, callback: AsyncCallback&lt;boolean&gt;): void;
1126
1127Obtains the screen hopping status of the target device. This API uses an asynchronous callback to return the result.
1128
1129> **NOTE**
1130>
1131> This API is deprecated since API version 10. You are advised to use [cooperate.deactivateCooperate](#cooperategetcooperateswitchstate11).
1132
1133**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
1134
1135**Parameters**
1136
1137| Name               | Type                         | Mandatory  | Description                           |
1138| --------             | ---------                    | ----  | ----------------------------    |
1139| networkId | string                       |  Yes   | Descriptor of the target device for screen hopping.            |
1140| callback             | AsyncCallback&lt;boolean&gt; |  Yes   | Callback used to return the result. The value **true** indicates that screen hopping is enabled, and the value **false** indicates the opposite.|
1141
1142**Error codes**
1143
1144For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
1145
1146| ID| Error Message         |
1147| -------- | ----------------- |
1148| 202 | Not system application. |
1149| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
1150
1151**Example**
1152
1153```ts
1154import { BusinessError } from '@ohos.base';
1155let deviceDescriptor = "networkId";
1156try {
1157  cooperate.getCrossingSwitchState(deviceDescriptor, (error: BusinessError, data: boolean) => {
1158    if (error) {
1159      console.log(`Get the status failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1160      return;
1161    }
1162    console.log(`Get the status success, data: ${JSON.stringify(data)}`);
1163  });
1164} catch (error) {
1165  console.log(`Get the status failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1166}
1167```
1168
1169## cooperate.getCrossingSwitchState<sup>(deprecated)</sup>
1170
1171getCrossingSwitchState(networkId: string): Promise&lt;boolean&gt;;
1172
1173Obtains the screen hopping status of the target device. This API uses a promise to return the result.
1174
1175> **NOTE**
1176>
1177> This API is deprecated since API version 10. You are advised to use [cooperate.getCooperateSwitchState](#cooperategetcooperateswitchstate11-1).
1178
1179**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
1180
1181**Parameters**
1182
1183| Name   | Type  | Mandatory  | Description                           |
1184| --------   | ---------  | ----  | ----------------------------    |
1185| networkId | string     |  Yes   | Descriptor of the target device for screen hopping.           |
1186
1187**Error codes**
1188
1189For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
1190
1191| ID| Error Message         |
1192| -------- | ----------------- |
1193| 202 | Not system application. |
1194| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
1195
1196**Return value**
1197
1198| Parameters                       | Description                    |
1199| -------------------        | ------------------------------- |
1200| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** indicates that screen hopping is enabled, and the value **false** indicates the opposite.|
1201
1202
1203
1204**Example**
1205
1206```ts
1207import { BusinessError } from '@ohos.base';
1208let deviceDescriptor = "networkId";
1209try {
1210  cooperate.getCrossingSwitchState(deviceDescriptor).then((data: boolean) => {
1211    console.log(`Get the status success, data: ${JSON.stringify(data)}`);
1212  }, (error: BusinessError) => {
1213    console.log(`Get the status failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1214  });
1215} catch (error) {
1216  console.log(`Get the status failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1217}
1218```
1219
1220
1221
1222## on('cooperate')<sup>(deprecated)</sup>
1223
1224on(type: 'cooperate', callback: Callback&lt;{ networkId: string, msg: CooperateMsg }&gt;): void;
1225
1226Enables listening for screen hopping status change events.
1227
1228> **NOTE**
1229>
1230> This API is deprecated since API version 10. You are advised to use [on('cooperateMessage')](#oncooperatemessage11).
1231
1232**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
1233
1234**Parameters**
1235
1236| Name               | Type                                                            | Mandatory| Description                           |
1237| --------             | ----------------------------                                    | ---- | ----------------------------   |
1238| type                 | string                                                          |  Yes | Event type. The value is **cooperate**.|
1239| callback             | Callback&lt;{ networkId: string, msg: [CooperateMsg](#cooperatemsgdeprecated) }&gt; |  Yes | Callback used to return the result.|
1240
1241**Error codes**
1242
1243For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
1244
1245| ID| Error Message         |
1246| -------- | ----------------- |
1247| 202 | Not system application. |
1248| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
1249
1250**Example**
1251
1252```ts
1253function callback(networkId: string, msg: cooperate.CooperateMsg) {
1254  console.log(`Keyboard mouse crossing event: ${JSON.stringify(networkId)}`);
1255  return false;
1256}
1257try {
1258  cooperate.on('cooperate', callback);
1259} catch (error) {
1260  console.log(`Register failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1261}
1262```
1263
1264
1265
1266## off('cooperate')<sup>(deprecated)</sup>
1267
1268off(type: 'cooperate', callback?: Callback&lt;void&gt;): void;
1269
1270Disables listening for screen hopping status change events.
1271
1272> **NOTE**
1273>
1274> This API is deprecated since API version 10. You are advised to use [off('cooperateMessage')](#offcooperatemessage11).
1275
1276**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
1277
1278**Parameters**
1279
1280| Name               | Type                                                             | Mandatory   | Description                          |
1281| --------             | ----------------------------                                     | ----   | ----------------------------   |
1282| type                 | string                                                           |  Yes   | Event type. The value is **cooperate**.|
1283| callback             | AsyncCallback&lt;void&gt; |  No | Callback to be unregistered. If this parameter is not specified, all callbacks registered by the current application will be unregistered.|
1284
1285**Error codes**
1286
1287For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
1288
1289| ID| Error Message         |
1290| -------- | ----------------- |
1291| 202 | Not system application. |
1292| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
1293
1294**Example**
1295
1296```ts
1297// Unregister a single callback.
1298function callbackOn(networkId: string, msg: cooperate.CooperateMsg) {
1299  console.log(`Keyboard mouse crossing event: ${JSON.stringify(networkId)}`);
1300  return false;
1301}
1302function callbackOff() {
1303  console.log(`Keyboard mouse crossing event`);
1304  return false;
1305}
1306try {
1307  cooperate.on('cooperate', callbackOn);
1308  cooperate.off('cooperate', callbackOff);
1309} catch (error) {
1310  console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1311}
1312```
1313```ts
1314// Unregister all callbacks.
1315function callbackOn(networkId: string, msg: cooperate.CooperateMsg) {
1316  console.log(`Keyboard mouse crossing event: ${JSON.stringify(networkId)}`);
1317  return false;
1318}
1319try {
1320  cooperate.on('cooperate', callbackOn);
1321  cooperate.off('cooperate');
1322} catch (error) {
1323  console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1324}
1325```
1326
1327
1328
1329##  CooperateMsg<sup>(deprecated)</sup>
1330
1331Represents a screen hopping message notification.
1332
1333> **NOTE**
1334>
1335> This API is deprecated since API version 10. You are advised to use [CooperateMessage](#cooperatemessage11).
1336
1337**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
1338
1339| Name                      | Value                            | Description                             |
1340| --------                     |  -----------------               |  -----------------               |
1341| COOPERATE_PREPARE |  0    |  The preparation for screen hopping is finished.  |
1342| COOPERATE_UNPREPARE |  1  |  The preparation for screen hopping is cancelled. |
1343| COOPERATE_ACTIVATE |  2   |  Screen hopping starts. |
1344| COOPERATE_ACTIVATE_SUCCESS | 3 | Starting screen hopping succeeds.|
1345| COOPERATE_ACTIVATE_FAIL | 4 | Starting screen hopping fails.|
1346| COOPERATE_DEACTIVATE_SUCCESS | 5 | Stopping screen hopping succeeds.|
1347| COOPERATE_DEACTIVATE_FAIL | 6 | Stopping screen hopping fails.|
1348| COOPERATE_SESSION_DISCONNECTED | 7 | The screen hopping session is disconnected.|
1349