1# @ohos.cooperate (键鼠穿越)(系统接口)
2
3键鼠穿越功能模块,提供两台或多台设备组网协同后键鼠共享能力,实现键鼠输入设备的跨设备协同操作。
4
5> **说明**
6>
7> - 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8>
9> - 本模块接口均为系统接口。
10
11## 导入模块
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
21准备键鼠穿越,使用Callback异步回调。
22
23**需要权限**:ohos.permission.COOPERATE_MANAGER
24
25**系统能力**:SystemCapability.Msdp.DeviceStatus.Cooperate
26
27**参数**:
28
29| 参数名   | 类型                      | 必填 | 说明                                                         |
30| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
31| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数,准备键鼠穿越成功时,err为undefined,否则为错误对象。 |
32
33**错误码:**
34
35以下错误码的详细介绍请参见[ohos.devicestatus错误码](errorcode-devicestatus.md)。
36
37| 错误码ID | 错误信息          |
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示例:
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
64准备键鼠穿越,使用Promise异步方式返回结果。
65
66**需要权限**:ohos.permission.COOPERATE_MANAGER
67
68**系统能力**:SystemCapability.Msdp.DeviceStatus.Cooperate
69
70**返回值:**
71
72| 参数                | 说明                      |
73| ------------------- | ------------------------- |
74| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
75
76**错误码:**
77
78以下错误码的详细介绍请参见[ohos.devicestatus错误码](errorcode-devicestatus.md)。
79
80| 错误码ID | 错误信息          |
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**示例**:
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
107取消键鼠穿越准备,使用Callback异步回调。
108
109**需要权限**:ohos.permission.COOPERATE_MANAGER
110
111**系统能力**: SystemCapability.Msdp.DeviceStatus.Cooperate
112
113| 参数名   | 类型                      | 必填 | 说明                                                         |
114| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
115| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数,取消键鼠穿越准备成功时,err为undefined,否则为错误对象。 |
116
117**错误码:**
118
119以下错误码的详细介绍请参见[ohos.devicestatus错误码](errorcode-devicestatus.md)。
120
121| 错误码ID | 错误信息          |
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**示例:**
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
148取消键鼠穿越准备,使用Promise异步回调。
149
150**需要权限**:ohos.permission.COOPERATE_MANAGER
151
152**系统能力**: SystemCapability.Msdp.DeviceStatus.Cooperate
153
154**返回值:**
155
156| 参数                | 说明                      |
157| ------------------- | ------------------------- |
158| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
159
160**错误码:**
161
162以下错误码的详细介绍请参见[ohos.devicestatus错误码](errorcode-devicestatus.md)。
163
164| 错误码ID | 错误信息          |
165| -------- | ----------------- |
166| 201 | Permission denied. |
167| 202 | Not system application. |
168
169**示例:**
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
190启动键鼠穿越,使用Callback异步回调。
191
192**需要权限**:ohos.permission.COOPERATE_MANAGER
193
194**系统能力**:SystemCapability.Msdp.DeviceStatus.Cooperate
195
196**参数:**
197
198| 参数名          | 类型                      | 必填 | 说明                                                         |
199| --------------- | ------------------------- | ---- | ------------------------------------------------------------ |
200| targetNetworkId | string                    | 是   | 键鼠穿越目标设备描述符。                                     |
201| inputDeviceId   | number                    | 是   | 待穿越输入设备标识符。                                       |
202| callback        | AsyncCallback&lt;void&gt; | 是   | 回调函数,键鼠穿越启动成功时,err为undefined,否则为错误对象。 |
203
204**错误码:**
205
206以下错误码的详细介绍请参见[ohos.devicestatus错误码](errorcode-devicestatus.md)。
207
208| 错误码ID | 错误信息          |
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 | Operation failed. |
214
215**示例:**
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
238启动键鼠穿越,使用Promise异步回调。
239
240**需要权限**:ohos.permission.COOPERATE_MANAGER
241
242**系统能力**: SystemCapability.Msdp.DeviceStatus.Cooperate
243
244**参数:**
245
246| 参数名          | 类型   | 必填 | 说明                     |
247| --------------- | ------ | ---- | ------------------------ |
248| targetNetworkId | string | 是   | 键鼠穿越目标设备描述符。 |
249| inputDeviceId   | number | 是   | 待穿越输入设备标识符。   |
250
251**返回值:**
252
253| 参数名              | 说明                      |
254| ------------------- | ------------------------- |
255| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
256
257**错误码:**
258
259以下错误码的详细介绍请参见[ohos.devicestatus错误码](errorcode-devicestatus.md)。
260
261| 错误码ID | 错误信息          |
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 | Operation failed. |
267
268**示例:**
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
291停止键鼠穿越,使用Callback异步回调。
292
293**需要权限**:ohos.permission.COOPERATE_MANAGER
294
295**系统能力**:SystemCapability.Msdp.DeviceStatus.Cooperate
296
297**参数:**
298
299| 参数名      | 类型                      | 必填 | 说明                                                         |
300| ----------- | ------------------------- | ---- | ------------------------------------------------------------ |
301| isUnchained | boolean                   | 是   | 是否关闭跨设备链路。 ture表示关闭跨设备链路,false表示不关闭。 |
302| callback    | AsyncCallback&lt;void&gt; | 是   | 回调函数,键鼠穿越停止成功时,err为undefined,否则为错误对象。 |
303
304**错误码:**
305
306以下错误码的详细介绍请参见[ohos.devicestatus错误码](errorcode-devicestatus.md)。
307
308| 错误码ID | 错误信息          |
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**示例**:
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
335停止键鼠穿越,使用Promise异步回调。
336
337**需要权限**:ohos.permission.COOPERATE_MANAGER
338
339**系统能力**:SystemCapability.Msdp.DeviceStatus.Cooperate
340
341**参数:**
342
343| 参数名      | 类型    | 必填 | 说明                                                         |
344| ----------- | ------- | ---- | ------------------------------------------------------------ |
345| isUnchained | boolean | 是   | 是否关闭跨设备链路。 ture表示关闭跨设备链路,false表示不关闭。 |
346
347**返回值:**
348
349| 参数名              | 说明                      |
350| ------------------- | ------------------------- |
351| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
352
353**错误码:**
354
355以下错误码的详细介绍请参见[ohos.devicestatus错误码](errorcode-devicestatus.md)。
356
357| 错误码ID | 错误信息          |
358| -------- | ----------------- |
359| 201 | Permission denied. |
360| 202 | Not system application. |
361
362**示例**:
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
383获取目标设备键鼠穿越开关的状态,使用Callback异步回调。
384
385**需要权限**:ohos.permission.COOPERATE_MANAGER
386
387**系统能力**:SystemCapability.Msdp.DeviceStatus.Cooperate
388
389**参数:**
390
391| 参数名    | 类型                         | 必填 | 说明                                                         |
392| --------- | ---------------------------- | ---- | ------------------------------------------------------------ |
393| networkId | string                       | 是   | 键鼠穿越目标设备描述符。                                     |
394| callback  | AsyncCallback&lt;boolean&gt; | 是   | 回调函数,返回ture表示目标设备键鼠穿越的开关开启,返回false表示开关未开启。 |
395
396**错误码:**
397
398以下错误码的详细介绍请参见[ohos.devicestatus错误码](errorcode-devicestatus.md)。
399
400| 错误码ID | 错误信息          |
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**示例:**
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
428获取目标设备键鼠穿越开关的状态,使用Promise异步方式返回结果。
429
430**需要权限**:ohos.permission.COOPERATE_MANAGER
431
432**系统能力**:SystemCapability.Msdp.DeviceStatus.Cooperate
433
434**参数**:
435
436| 参数名    | 类型   | 必填 | 说明                     |
437| --------- | ------ | ---- | ------------------------ |
438| networkId | string | 是   | 键鼠穿越目标设备描述符。 |
439
440**返回值**:
441
442| 参数                   | 说明                                                         |
443| ---------------------- | ------------------------------------------------------------ |
444| Promise&lt;boolean&gt; | Promise对象,返回ture表示目标设备键鼠穿越的开关开启,返回false表示开关未开启。 |
445
446**错误码:**
447
448以下错误码的详细介绍请参见[ohos.devicestatus错误码](errorcode-devicestatus.md)。
449
450| 错误码ID | 错误信息          |
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**示例**:
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
478注册监听键鼠穿越状态。
479
480**需要权限**:ohos.permission.COOPERATE_MANAGER
481
482**系统能力**:SystemCapability.Msdp.DeviceStatus.Cooperate
483
484**参数**:
485
486| 参数名   | 类型                                                  | 必填 | 说明                                 |
487| -------- | ----------------------------------------------------- | ---- | ------------------------------------ |
488| type     | string                                                | 是   | 监听类型,取值为'cooperateMessage'   |
489| callback | Callback&lt;[CooperateMessage](#cooperatemessage11)&gt; | 是   | 回调函数,异步返回键鼠穿越状态消息。 |
490
491**错误码:**
492
493以下错误码的详细介绍请参见[ohos.devicestatus错误码](errorcode-devicestatus.md)。
494
495| 错误码ID | 错误信息          |
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**示例**:
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
521取消监听键鼠穿越状态。
522
523**需要权限**:ohos.permission.COOPERATE_MANAGER
524
525**系统能力**:SystemCapability.Msdp.DeviceStatus.Cooperate
526
527**参数:**
528
529| 参数名   | 类型                                                  | 必填 | 说明                                                         |
530| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ |
531| type     | string                                                | 是   | 监听类型,取值为'cooperate'。                                |
532| callback | Callback&lt;[CooperateMessage](#cooperatemessage11)&gt; | 否   | 需要取消注册的回调函数,若无此参数,则取消当前应用注册的所有回调函数。 |
533
534**错误码:**
535
536以下错误码的详细介绍请参见[ohos.devicestatus错误码](errorcode-devicestatus.md)。
537
538| 错误码ID | 错误信息          |
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**示例**:
545
546```ts
547// 取消注册单个回调函数
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// 取消注册所有回调函数
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
583注册监听指定设备鼠标光标位置。
584
585**需要权限**:ohos.permission.COOPERATE_MANAGER
586
587**系统能力**:SystemCapability.Msdp.DeviceStatus.Cooperate
588
589**参数**:
590
591| 参数名   | 类型                                                  | 必填 | 说明                                 |
592| -------- | ----------------------------------------------------- | ---- | ------------------------------------ |
593| type     | string                                                | 是   | 监听类型,取值为'cooperateMouse'   |
594| networkId| string                                                | 是   | 目标设备描述符   |
595| callback | Callback&lt;[MouseLocation](#mouselocation12)&gt; | 是   | 回调函数,异步返回指定监听设备鼠标光标位置信息。 |
596
597**错误码:**
598
599以下错误码的详细介绍请参见[ohos.devicestatus错误码](errorcode-devicestatus.md)。
600
601| 错误码ID | 错误信息          |
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**示例**:
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
628取消监听指定设备鼠标光标位置。
629
630**需要权限**:ohos.permission.COOPERATE_MANAGER
631
632**系统能力**:SystemCapability.Msdp.DeviceStatus.Cooperate
633
634**参数:**
635
636| 参数名   | 类型                                                  | 必填 | 说明                                                         |
637| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ |
638| type     | string                                                | 是   | 监听类型,取值为'cooperateMouse'。                                |
639| networkId| string                                                | 是   | 目标设备描述符   |
640| callback | Callback&lt;[MouseLocation](#mouselocation12)&gt; | 否   | 需要取消注册的回调函数,若无此参数,则取消当前应用注册的所有回调函数。 |
641
642**错误码:**
643
644以下错误码的详细介绍请参见[ohos.devicestatus错误码](errorcode-devicestatus.md)。
645
646| 错误码ID | 错误信息          |
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**示例**:
653
654```ts
655// 取消注册单个回调函数
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// 取消注册所有回调函数
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
691键鼠穿越的消息。
692
693**系统能力**:SystemCapability.Msdp.DeviceStatus.Cooperate
694
695| 名称      | 类型           | 可读 | 可写 | 说明                     |
696| --------- | -------------- | ---- | ---- | ------------------------ |
697| networkId | string         | 是   | 否   | 键鼠穿越目标设备描述符。 |
698| state     | CooperateState | 是   | 否   | 键鼠穿越的状态。         |
699
700
701## MouseLocation<sup>12+</sup>
702
703键鼠穿越的位置。
704
705**系统能力**:SystemCapability.Msdp.DeviceStatus.Cooperate
706
707| 名称           | 类型            | 可读 | 可写 | 说明                           |
708| ---------      | -------------- | ---- | ---- | ------------------------       |
709| displayX       | number         | 是   | 否   | 鼠标指针位于屏幕的X坐标上的位置。 |
710| displayY       | number         | 是   | 否   | 鼠标指针位于屏幕的y坐标上的位置。 |
711| displayWidth   | number         | 是   | 否   | 屏幕宽度。                      |
712| displayHeight  | number         | 是   | 否   | 屏幕高度。                      |
713
714
715
716## CooperateState<sup>11+</sup>
717
718键鼠穿越的状态。
719
720**系统能力**:SystemCapability.Msdp.DeviceStatus.Cooperate
721
722| 名称                           | 类型    | 可读 | 可写 | 说明                   |
723| ------------------------------ | ------ | ---- | ---- | ---------------------- |
724| COOPERATE_PREPARE              | number | 是   | 否   | 表示准备键鼠穿越。     |
725| COOPERATE_UNPREPARE            | number | 是   | 否   | 表示取消键鼠穿越准备。 |
726| COOPERATE_ACTIVATE             | number | 是   | 否   | 表示启动键鼠穿越。     |
727| COOPERATE_ACTIVATE_SUCCESS     | number | 是   | 否   | 表示键鼠穿越启动成功。 |
728| COOPERATE_ACTIVATE_FAIL        | number | 是   | 否   | 表示键鼠穿越启动失败。 |
729| COOPERATE_DEACTIVATE_SUCCESS   | number | 是   | 否   | 表示键鼠穿越停止成功。 |
730| COOPERATE_DEACTIVATE_FAIL      | number | 是   | 否   | 表示键鼠穿越停止失败。 |
731| COOPERATE_SESSION_DISCONNECTED | number | 是   | 否   | 表示键鼠穿越会话断开。 |
732| COOPERATE_ACTIVATE_FAILURE     | number | 是   | 否   | 表示键鼠穿越无法启动。 |
733| COOPERATE_DEACTIVATE_FAILURE   | number | 是   | 否   | 表示键鼠穿越无法停止。 |
734
735
736## MouseLocation<sup>12+</sup>
737
738鼠标光标位置信息。
739
740**系统能力**:SystemCapability.Msdp.DeviceStatus.Cooperate
741
742| 名称           | 类型           | 可读 | 可写 | 说明                     |
743| ---------     | -------------- | ---- | ---- | ------------------------ |
744| displayX      | number         | 是   | 否   | 鼠标X坐标位置。 |
745| displayY      | number         | 是   | 否   | 鼠标Y坐标位置。 |
746| displayWidth  | number         | 是   | 否   | 鼠标所在屏幕宽度。 |
747| displayHeight | number         | 是   | 否   | 鼠标所在屏幕高度。 |
748
749
750## cooperate.prepare<sup>(deprecated)</sup>
751
752prepare(callback: AsyncCallback&lt;void&gt;): void;
753
754准备键鼠穿越,使用Callback异步回调。
755
756> **说明:**
757>
758> 从API version 10开始不在维护。建议使用[cooperate.prepareCooperate](#cooperatepreparecooperate11)替代
759
760**系统能力**: SystemCapability.Msdp.DeviceStatus.Cooperate
761
762**参数**:
763
764| 参数名    | 类型      | 必填  | 说明    |
765| -------- | ------------------------- | ---- | --------------------------- |
766| callback | AsyncCallback&lt;void&gt;  | 是 |回调函数,准备键鼠穿越成功时,err为undefined,否则为错误对象。   |
767
768**错误码:**
769
770以下错误码的详细介绍请参见[ohos.devicestatus错误码](errorcode-devicestatus.md)。
771
772| 错误码ID | 错误信息          |
773| -------- | ----------------- |
774| 202 | Not system application. |
775| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
776
777**示例**:
778
779```ts
780import { BusinessError } from '@ohos.base';
781try {
782  cooperate.prepare((error: BusinessError) => {
783    if (error) {
784      console.log(`Keyboard mouse crossing prepare failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
785      return;
786    }
787    console.log(`Keyboard mouse crossing prepare success.`);
788  });
789} catch (error) {
790  console.log(`Keyboard mouse crossing prepare failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
791}
792```
793
794## cooperate.prepare<sup>(deprecated)</sup>
795
796prepare(): Promise&lt;void&gt;;
797
798准备键鼠穿越,使用Promise异步方式返回结果。
799
800> **说明:**
801>
802> 从API version 10开始不在维护。建议使用[cooperate.prepareCooperate](#cooperatepreparecooperate11-1)替代
803
804**系统能力**:SystemCapability.Msdp.DeviceStatus.Cooperate
805
806**返回值**:
807
808| 参数                 | 说明                     |
809| ------------------- | ------------------------------- |
810| Promise&lt;void&gt;      | 无返回结果的Promise对象。 |
811
812**错误码:**
813
814以下错误码的详细介绍请参见[ohos.devicestatus错误码](errorcode-devicestatus.md)。
815
816| 错误码ID | 错误信息          |
817| -------- | ----------------- |
818| 202 | Not system application. |
819| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
820
821**示例**:
822
823```ts
824import { BusinessError } from '@ohos.base';
825try {
826  cooperate.prepare().then(() => {
827    console.log(`Keyboard mouse crossing prepare success.`);
828  }, (error: BusinessError) => {
829    console.log(`Keyboard mouse crossing prepare failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
830  });
831} catch (error) {
832  console.log(`Keyboard mouse crossing prepare failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
833}
834```
835
836
837
838## cooperate.unprepare<sup>(deprecated)</sup>
839
840unprepare(callback: AsyncCallback&lt;void&gt;): void;
841
842取消键鼠穿越准备,使用Callback异步回调。
843
844> **说明:**
845>
846> 从API version 10开始不在维护。建议使用[cooperate.unprepareCooperate](#cooperateunpreparecooperate11)替代
847
848**系统能力**: SystemCapability.Msdp.DeviceStatus.Cooperate
849
850| 参数名   | 类型                      | 必填 | 说明                                       |
851| -------- | ------------------------- | ---- | ------------------------------------------ |
852| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数,取消键鼠穿越准备成功时,err为undefined,否则为错误对象。 |
853
854**错误码:**
855
856以下错误码的详细介绍请参见[ohos.devicestatus错误码](errorcode-devicestatus.md)。
857
858| 错误码ID | 错误信息          |
859| -------- | ----------------- |
860| 202 | Not system application. |
861| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
862
863**示例**:
864
865```ts
866import { BusinessError } from '@ohos.base';
867try {
868  cooperate.unprepare((error: BusinessError) => {
869    if (error) {
870      console.log(`Keyboard mouse crossing unprepare failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
871      return;
872    }
873    console.log(`Keyboard mouse crossing unprepare success.`);
874  });
875} catch (error) {
876  console.log(`Keyboard mouse crossing unprepare failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
877}
878```
879
880## cooperate.unprepare<sup>(deprecated)</sup>
881
882unprepare(): Promise&lt;void&gt;;
883
884取消键鼠穿越准备,使用Promise异步回调。
885
886> **说明:**
887>
888> 从API version 10开始不在维护。建议使用[cooperate.unprepareCooperate](#cooperateunpreparecooperate11-1)替代
889
890**系统能力**: SystemCapability.Msdp.DeviceStatus.Cooperate
891
892**返回值**:
893
894| 参数                | 说明                                          |
895| ------------------- | --------------------------------------------- |
896| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
897
898**错误码:**
899
900以下错误码的详细介绍请参见[ohos.devicestatus错误码](errorcode-devicestatus.md)。
901
902| 错误码ID | 错误信息          |
903| -------- | ----------------- |
904| 202 | Not system application. |
905| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
906
907**示例:**
908
909```ts
910import { BusinessError } from '@ohos.base';
911try {
912  cooperate.unprepare().then(() => {
913    console.log(`Keyboard mouse crossing unprepare success.`);
914  }, (error: BusinessError) => {
915    console.log(`Keyboard mouse crossing unprepare failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
916  });
917} catch (error) {
918  console.log(`Keyboard mouse crossing unprepare failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
919}
920```
921
922
923
924## cooperate.activate<sup>(deprecated)</sup>
925
926activate(targetNetworkId: string, inputDeviceId: number, callback: AsyncCallback&lt;void&gt;): void;
927
928启动键鼠穿越,使用Callback异步回调。
929
930> **说明:**
931>
932> 从API version 10开始不在维护。建议使用[cooperate.activateCooperate](#cooperateactivatecooperate11)替代
933
934**系统能力**:SystemCapability.Msdp.DeviceStatus.Cooperate
935
936**参数**:
937
938| 参数名                | 类型                          | 必填  | 说明                            |
939| --------             | ---------------------------- | ----  | ----------------------------   |
940| targetNetworkId | string                       |  是   | 键鼠穿越目标设备描述符。             |
941| inputDeviceId | number                       |  是   | 待穿越输入设备标识符。 |
942| callback             | AsyncCallback&lt;void&gt; |  是    | 回调函数,键鼠穿越启动成功时,err为undefined,否则为错误对象。 |
943
944**错误码:**
945
946以下错误码的详细介绍请参见[ohos.devicestatus错误码](errorcode-devicestatus.md)。
947
948| 错误码ID | 错误信息 |
949| -------- | ---------------------------------------- |
950| 20900001 | Operation failed.|
951| 202 | Not system application. |
952| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
953
954**示例**:
955
956```ts
957import { BusinessError } from '@ohos.base';
958let targetNetworkId = "networkId";
959let inputDeviceId = 0;
960try {
961  cooperate.activate(targetNetworkId, inputDeviceId, (error: BusinessError) => {
962    if (error) {
963      console.log(`Start Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
964      return;
965    }
966    console.log(`Start Keyboard mouse crossing success.`);
967  });
968} catch (error) {
969  console.log(`Start Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
970}
971```
972
973## cooperate.activate<sup>(deprecated)</sup>
974
975activate(targetNetworkId: string, inputDeviceId: number): Promise&lt;void&gt;;
976
977启动键鼠穿越,使用Promise异步回调。
978
979> **说明:**
980>
981> 从API version 10开始不在维护。建议使用[cooperate.activateCooperate](#cooperateactivatecooperate11-1)替代
982
983**系统能力**: SystemCapability.Msdp.DeviceStatus.Cooperate
984
985**参数**:
986
987| 参数名                | 类型                          | 必填  | 说明                            |
988| --------             | ---------------------------- | ----  | ----------------------------   |
989| targetNetworkId | string                       |  是   | 键鼠穿越目标设备描述符。             |
990| inputDeviceId | number                       |  是   | 待穿越输入设备标识符。 |
991
992
993
994**返回值**:
995
996| 参数名                  | 说明                             |
997| ---------------------- | ------------------------------- |
998| Promise&lt;void&gt; | 无返回结果的Promise对象。     |
999
1000**错误码:**
1001
1002以下错误码的详细介绍请参见[ohos.devicestatus错误码](errorcode-devicestatus.md)。
1003
1004| 错误码ID | 错误信息 |
1005| -------- | ---------------------------------------- |
1006| 20900001 | Operation failed.   |
1007| 202 | Not system application. |
1008| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
1009
1010**示例**:
1011
1012```ts
1013import { BusinessError } from '@ohos.base';
1014let targetNetworkId = "networkId";
1015let inputDeviceId = 0;
1016try {
1017 cooperate.activate(targetNetworkId, inputDeviceId).then(() => {
1018    console.log(`Start Keyboard mouse crossing success.`);
1019  }, (error: BusinessError) => {
1020    console.log(`Start Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1021  });
1022} catch (error) {
1023  console.log(`Start Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1024}
1025```
1026
1027
1028
1029## cooperate.deactivate<sup>(deprecated)</sup>
1030
1031deactivate(isUnchained: boolean, callback: AsyncCallback&lt;void&gt;): void;
1032
1033停止键鼠穿越,使用Callback异步回调。
1034
1035> **说明:**
1036>
1037> 从API version 10开始不在维护。建议使用[cooperate.deactivateCooperate](#cooperatedeactivatecooperate11)替代
1038
1039**系统能力**:SystemCapability.Msdp.DeviceStatus.Cooperate
1040
1041**参数**:
1042
1043| 参数名                | 类型                          | 必填  | 说明                            |
1044| --------             | ---------------------------- | ----  | ----------------------------   |
1045| isUnchained | boolean | 是 | 是否关闭跨设备链路。<br> ture表示关闭跨设备链路,false表示不关闭。 |
1046| callback     | AsyncCallback&lt;void&gt; |  是   | 回调函数,键鼠穿越停止成功时,err为undefined,否则为错误对象。|
1047
1048**错误码:**
1049
1050以下错误码的详细介绍请参见[ohos.devicestatus错误码](errorcode-devicestatus.md)。
1051
1052| 错误码ID | 错误信息          |
1053| -------- | ----------------- |
1054| 202 | Not system application. |
1055| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
1056
1057**示例**:
1058
1059```ts
1060import { BusinessError } from '@ohos.base';
1061try {
1062  cooperate.deactivate(false, (error: BusinessError) => {
1063    if (error) {
1064      console.log(`Stop Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1065      return;
1066    }
1067    console.log(`Stop Keyboard mouse crossing success.`);
1068  });
1069} catch (error) {
1070  console.log(`Stop Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1071}
1072```
1073
1074## cooperate.deactivate<sup>(deprecated)</sup>
1075
1076deactivate(isUnchained: boolean): Promise&lt;void&gt;;
1077
1078停止键鼠穿越,使用Promise异步回调。
1079
1080> **说明:**
1081>
1082> 从API version 10开始不在维护。建议使用[cooperate.deactivateCooperate](#cooperatedeactivatecooperate11-1)替代
1083
1084**系统能力**:SystemCapability.Msdp.DeviceStatus.Cooperate
1085
1086**参数**:
1087
1088| 参数名      | 类型    | 必填 | 说明               |
1089| ----------- | ------- | ---- | ------------------ |
1090| isUnchained | boolean | 是   | 是否关闭跨设备链路。<br> ture表示关闭跨设备链路,false表示不关闭。 |
1091
1092
1093
1094**返回值**:
1095
1096| 参数名                | 说明                            |
1097| --------             | ----------------------------   |
1098| Promise&lt;void&gt; |  无返回结果的Promise对象。      |
1099
1100**错误码:**
1101
1102以下错误码的详细介绍请参见[ohos.devicestatus错误码](errorcode-devicestatus.md)。
1103
1104| 错误码ID | 错误信息          |
1105| -------- | ----------------- |
1106| 202 | Not system application. |
1107
1108**示例**:
1109
1110```ts
1111import { BusinessError } from '@ohos.base';
1112try {
1113  cooperate.deactivate(false).then(() => {
1114    console.log(`Stop Keyboard mouse crossing success.`);
1115  }, (error: BusinessError) => {
1116    console.log(`Stop Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1117  });
1118} catch (error) {
1119  console.log(`Stop Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1120}
1121```
1122
1123
1124
1125## cooperate.getCrossingSwitchState<sup>(deprecated)</sup>
1126
1127getCrossingSwitchState(networkId: string, callback: AsyncCallback&lt;boolean&gt;): void;
1128
1129获取目标设备键鼠穿越开关的状态,使用Callback异步回调。
1130
1131> **说明:**
1132>
1133> 从API version 10开始不在维护。建议使用[cooperate.getCooperateSwitchState](#cooperategetcooperateswitchstate11)替代
1134
1135**系统能力**:SystemCapability.Msdp.DeviceStatus.Cooperate
1136
1137**参数**:
1138
1139| 参数名                | 类型                          | 必填   | 说明                            |
1140| --------             | ---------                    | ----  | ----------------------------    |
1141| networkId | string                       |  是    | 键鼠穿越目标设备描述符。             |
1142| callback             | AsyncCallback&lt;boolean&gt; |  是    | 回调函数,返回ture表示目标设备键鼠穿越的开关开启,返回false表示开关未开启。 |
1143
1144**错误码:**
1145
1146以下错误码的详细介绍请参见[ohos.devicestatus错误码](errorcode-devicestatus.md)。
1147
1148| 错误码ID | 错误信息          |
1149| -------- | ----------------- |
1150| 202 | Not system application. |
1151| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
1152
1153**示例**:
1154
1155```ts
1156import { BusinessError } from '@ohos.base';
1157let deviceDescriptor = "networkId";
1158try {
1159  cooperate.getCrossingSwitchState(deviceDescriptor, (error: BusinessError, data: boolean) => {
1160    if (error) {
1161      console.log(`Get the status failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1162      return;
1163    }
1164    console.log(`Get the status success, data: ${JSON.stringify(data)}`);
1165  });
1166} catch (error) {
1167  console.log(`Get the status failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1168}
1169```
1170
1171## cooperate.getCrossingSwitchState<sup>(deprecated)</sup>
1172
1173getCrossingSwitchState(networkId: string): Promise&lt;boolean&gt;;
1174
1175获取目标设备键鼠穿越开关的状态,使用Promise异步方式返回结果。
1176
1177> **说明:**
1178>
1179> 从API version 10开始不在维护。建议使用[cooperate.getCooperateSwitchState](#cooperategetcooperateswitchstate11-1)替代
1180
1181**系统能力**:SystemCapability.Msdp.DeviceStatus.Cooperate
1182
1183**参数**:
1184
1185| 参数名    | 类型   | 必填   | 说明                            |
1186| --------   | ---------  | ----  | ----------------------------    |
1187| networkId | string     |  是    | 键鼠穿越目标设备描述符。            |
1188
1189**错误码:**
1190
1191以下错误码的详细介绍请参见[ohos.devicestatus错误码](errorcode-devicestatus.md)。
1192
1193| 错误码ID | 错误信息          |
1194| -------- | ----------------- |
1195| 202 | Not system application. |
1196| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
1197
1198**返回值**:
1199
1200| 参数                        | 说明                     |
1201| -------------------        | ------------------------------- |
1202| Promise&lt;boolean&gt; | Promise对象,返回ture表示目标设备键鼠穿越的开关开启,返回false表示开关未开启。 |
1203
1204
1205
1206**示例**:
1207
1208```ts
1209import { BusinessError } from '@ohos.base';
1210let deviceDescriptor = "networkId";
1211try {
1212  cooperate.getCrossingSwitchState(deviceDescriptor).then((data: boolean) => {
1213    console.log(`Get the status success, data: ${JSON.stringify(data)}`);
1214  }, (error: BusinessError) => {
1215    console.log(`Get the status failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1216  });
1217} catch (error) {
1218  console.log(`Get the status failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1219}
1220```
1221
1222
1223
1224## on('cooperate')<sup>(deprecated)</sup>
1225
1226on(type: 'cooperate', callback: Callback&lt;{ networkId: string, msg: CooperateMsg }&gt;): void;
1227
1228注册监听键鼠穿越状态。
1229
1230> **说明:**
1231>
1232> 从API version 10开始不在维护。建议使用[on('cooperateMessage')](#oncooperatemessage11)替代
1233
1234**系统能力**:SystemCapability.Msdp.DeviceStatus.Cooperate
1235
1236**参数**:
1237
1238| 参数名                | 类型                                                             | 必填 | 说明                            |
1239| --------             | ----------------------------                                    | ---- | ----------------------------   |
1240| type                 | string                                                          |  是  | 监听类型,取值为'cooperate' |
1241| callback             | Callback&lt;{ networkId: string, msg: [CooperateMsg](#cooperatemsgdeprecated) }&gt; |  是  | 回调函数,异步返回键鼠穿越状态消息。 |
1242
1243**错误码:**
1244
1245以下错误码的详细介绍请参见[ohos.devicestatus错误码](errorcode-devicestatus.md)。
1246
1247| 错误码ID | 错误信息          |
1248| -------- | ----------------- |
1249| 202 | Not system application. |
1250| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
1251
1252**示例**:
1253
1254```ts
1255function callback(networkId: string, msg: cooperate.CooperateMsg) {
1256  console.log(`Keyboard mouse crossing event: ${JSON.stringify(networkId)}`);
1257  return false;
1258}
1259try {
1260  cooperate.on('cooperate', callback);
1261} catch (error) {
1262  console.log(`Register failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1263}
1264```
1265
1266
1267
1268## off('cooperate')<sup>(deprecated)</sup>
1269
1270off(type: 'cooperate', callback?: Callback&lt;void&gt;): void;
1271
1272取消监听键鼠穿越状态。
1273
1274> **说明:**
1275>
1276> 从API version 10开始不在维护。建议使用[off('cooperateMessage')](#offcooperatemessage11)替代
1277
1278**系统能力**:SystemCapability.Msdp.DeviceStatus.Cooperate
1279
1280**参数**:
1281
1282| 参数名                | 类型                                                              | 必填    | 说明                           |
1283| --------             | ----------------------------                                     | ----   | ----------------------------   |
1284| type                 | string                                                           |  是    | 监听类型,取值为'cooperate'。 |
1285| callback             | AsyncCallback&lt;void&gt; |  否  | 需要取消注册的回调函数,若无此参数,则取消当前应用注册的所有回调函数。 |
1286
1287**错误码:**
1288
1289以下错误码的详细介绍请参见[ohos.devicestatus错误码](errorcode-devicestatus.md)。
1290
1291| 错误码ID | 错误信息          |
1292| -------- | ----------------- |
1293| 202 | Not system application. |
1294| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
1295
1296**示例**:
1297
1298```ts
1299// 取消注册单个回调函数
1300function callbackOn(networkId: string, msg: cooperate.CooperateMsg) {
1301  console.log(`Keyboard mouse crossing event: ${JSON.stringify(networkId)}`);
1302  return false;
1303}
1304function callbackOff() {
1305  console.log(`Keyboard mouse crossing event`);
1306  return false;
1307}
1308try {
1309  cooperate.on('cooperate', callbackOn);
1310  cooperate.off('cooperate', callbackOff);
1311} catch (error) {
1312  console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1313}
1314```
1315```ts
1316// 取消注册所有回调函数
1317function callbackOn(networkId: string, msg: cooperate.CooperateMsg) {
1318  console.log(`Keyboard mouse crossing event: ${JSON.stringify(networkId)}`);
1319  return false;
1320}
1321try {
1322  cooperate.on('cooperate', callbackOn);
1323  cooperate.off('cooperate');
1324} catch (error) {
1325  console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1326}
1327```
1328
1329
1330
1331##  CooperateMsg<sup>(deprecated)</sup>
1332
1333键鼠穿越的消息通知。
1334
1335> **说明:**
1336>
1337> 从API version 10开始不在维护。建议使用[CooperateMessage](#cooperatemessage11)替代
1338
1339**系统能力**:SystemCapability.Msdp.DeviceStatus.Cooperate
1340
1341| 名称                       | 值                             | 说明                              |
1342| --------                     |  -----------------               |  -----------------               |
1343| COOPERATE_PREPARE |  0    |  表示准备键鼠穿越。   |
1344| COOPERATE_UNPREPARE |  1  |  表示取消键鼠穿越准备。  |
1345| COOPERATE_ACTIVATE |  2   |  表示启动键鼠穿越。  |
1346| COOPERATE_ACTIVATE_SUCCESS | 3 | 表示键鼠穿越启动成功。 |
1347| COOPERATE_ACTIVATE_FAIL | 4 | 表示键鼠穿越启动失败。 |
1348| COOPERATE_DEACTIVATE_SUCCESS | 5 | 表示键鼠穿越停止成功。 |
1349| COOPERATE_DEACTIVATE_FAIL | 6 | 表示键鼠穿越停止失败。 |
1350| COOPERATE_SESSION_DISCONNECTED | 7 | 表示键鼠穿越会话断开。 |
1351