• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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         | 是   | 否   | 屏幕宽度,单位:px。                      |
712| displayHeight  | number         | 是   | 否   | 屏幕高度,单位:px。                      |
713
714## CooperateState<sup>11+</sup>
715
716键鼠穿越的状态。
717
718**系统能力**:SystemCapability.Msdp.DeviceStatus.Cooperate
719
720| 名称                           | 类型    | 可读 | 可写 | 说明                   |
721| ------------------------------ | ------ | ---- | ---- | ---------------------- |
722| COOPERATE_PREPARE              | number | 是   | 否   | 表示准备键鼠穿越。     |
723| COOPERATE_UNPREPARE            | number | 是   | 否   | 表示取消键鼠穿越准备。 |
724| COOPERATE_ACTIVATE             | number | 是   | 否   | 表示启动键鼠穿越。     |
725| COOPERATE_ACTIVATE_SUCCESS     | number | 是   | 否   | 表示键鼠穿越启动成功。 |
726| COOPERATE_ACTIVATE_FAIL        | number | 是   | 否   | 表示键鼠穿越启动失败。 |
727| COOPERATE_DEACTIVATE_SUCCESS   | number | 是   | 否   | 表示键鼠穿越停止成功。 |
728| COOPERATE_DEACTIVATE_FAIL      | number | 是   | 否   | 表示键鼠穿越停止失败。 |
729| COOPERATE_SESSION_DISCONNECTED | number | 是   | 否   | 表示键鼠穿越会话断开。 |
730| COOPERATE_ACTIVATE_FAILURE     | number | 是   | 否   | 表示键鼠穿越无法启动。 |
731| COOPERATE_DEACTIVATE_FAILURE   | number | 是   | 否   | 表示键鼠穿越无法停止。 |
732
733
734## MouseLocation<sup>12+</sup>
735
736鼠标光标位置信息。
737
738**系统能力**:SystemCapability.Msdp.DeviceStatus.Cooperate
739
740| 名称           | 类型           | 可读 | 可写 | 说明                     |
741| ---------     | -------------- | ---- | ---- | ------------------------ |
742| displayX      | number         | 是   | 否   | 鼠标X坐标位置。 |
743| displayY      | number         | 是   | 否   | 鼠标Y坐标位置。 |
744| displayWidth  | number         | 是   | 否   | 鼠标所在屏幕宽度,单位:px。 |
745| displayHeight | number         | 是   | 否   | 鼠标所在屏幕高度,单位:px。 |
746
747
748## cooperate.prepare<sup>(deprecated)</sup>
749
750prepare(callback: AsyncCallback&lt;void&gt;): void;
751
752准备键鼠穿越,使用Callback异步回调。
753
754> **说明:**
755>
756> 从API version 10开始不在维护。建议使用[cooperate.prepareCooperate](#cooperatepreparecooperate11)替代
757
758**系统能力**: SystemCapability.Msdp.DeviceStatus.Cooperate
759
760**参数**:
761
762| 参数名    | 类型      | 必填  | 说明    |
763| -------- | ------------------------- | ---- | --------------------------- |
764| callback | AsyncCallback&lt;void&gt;  | 是 |回调函数,准备键鼠穿越成功时,err为undefined,否则为错误对象。   |
765
766**错误码:**
767
768以下错误码的详细介绍请参见[ohos.devicestatus错误码](errorcode-devicestatus.md)。
769
770| 错误码ID | 错误信息          |
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**示例**:
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
796准备键鼠穿越,使用Promise异步方式返回结果。
797
798> **说明:**
799>
800> 从API version 10开始不在维护。建议使用[cooperate.prepareCooperate](#cooperatepreparecooperate11-1)替代
801
802**系统能力**:SystemCapability.Msdp.DeviceStatus.Cooperate
803
804**返回值**:
805
806| 参数                 | 说明                     |
807| ------------------- | ------------------------------- |
808| Promise&lt;void&gt;      | 无返回结果的Promise对象。 |
809
810**错误码:**
811
812以下错误码的详细介绍请参见[ohos.devicestatus错误码](errorcode-devicestatus.md)。
813
814| 错误码ID | 错误信息          |
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**示例**:
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
840取消键鼠穿越准备,使用Callback异步回调。
841
842> **说明:**
843>
844> 从API version 10开始不在维护。建议使用[cooperate.unprepareCooperate](#cooperateunpreparecooperate11)替代
845
846**系统能力**: SystemCapability.Msdp.DeviceStatus.Cooperate
847
848| 参数名   | 类型                      | 必填 | 说明                                       |
849| -------- | ------------------------- | ---- | ------------------------------------------ |
850| callback | AsyncCallback&lt;void&gt; | 是   | 回调函数,取消键鼠穿越准备成功时,err为undefined,否则为错误对象。 |
851
852**错误码:**
853
854以下错误码的详细介绍请参见[ohos.devicestatus错误码](errorcode-devicestatus.md)。
855
856| 错误码ID | 错误信息          |
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**示例**:
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
882取消键鼠穿越准备,使用Promise异步回调。
883
884> **说明:**
885>
886> 从API version 10开始不在维护。建议使用[cooperate.unprepareCooperate](#cooperateunpreparecooperate11-1)替代
887
888**系统能力**: SystemCapability.Msdp.DeviceStatus.Cooperate
889
890**返回值**:
891
892| 参数                | 说明                                          |
893| ------------------- | --------------------------------------------- |
894| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
895
896**错误码:**
897
898以下错误码的详细介绍请参见[ohos.devicestatus错误码](errorcode-devicestatus.md)。
899
900| 错误码ID | 错误信息          |
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**示例:**
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
926启动键鼠穿越,使用Callback异步回调。
927
928> **说明:**
929>
930> 从API version 10开始不在维护。建议使用[cooperate.activateCooperate](#cooperateactivatecooperate11)替代
931
932**系统能力**:SystemCapability.Msdp.DeviceStatus.Cooperate
933
934**参数**:
935
936| 参数名                | 类型                          | 必填  | 说明                            |
937| --------             | ---------------------------- | ----  | ----------------------------   |
938| targetNetworkId | string                       |  是   | 键鼠穿越目标设备描述符。             |
939| inputDeviceId | number                       |  是   | 待穿越输入设备标识符。 |
940| callback             | AsyncCallback&lt;void&gt; |  是    | 回调函数,键鼠穿越启动成功时,err为undefined,否则为错误对象。 |
941
942**错误码:**
943
944以下错误码的详细介绍请参见[ohos.devicestatus错误码](errorcode-devicestatus.md)。
945
946| 错误码ID | 错误信息 |
947| -------- | ---------------------------------------- |
948| 20900001 | Operation failed.|
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**示例**:
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
975启动键鼠穿越,使用Promise异步回调。
976
977> **说明:**
978>
979> 从API version 10开始不在维护。建议使用[cooperate.activateCooperate](#cooperateactivatecooperate11-1)替代
980
981**系统能力**: SystemCapability.Msdp.DeviceStatus.Cooperate
982
983**参数**:
984
985| 参数名                | 类型                          | 必填  | 说明                            |
986| --------             | ---------------------------- | ----  | ----------------------------   |
987| targetNetworkId | string                       |  是   | 键鼠穿越目标设备描述符。             |
988| inputDeviceId | number                       |  是   | 待穿越输入设备标识符。 |
989
990
991
992**返回值**:
993
994| 参数名                  | 说明                             |
995| ---------------------- | ------------------------------- |
996| Promise&lt;void&gt; | 无返回结果的Promise对象。     |
997
998**错误码:**
999
1000以下错误码的详细介绍请参见[ohos.devicestatus错误码](errorcode-devicestatus.md)。
1001
1002| 错误码ID | 错误信息 |
1003| -------- | ---------------------------------------- |
1004| 20900001 | Operation failed.   |
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**示例**:
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
1031停止键鼠穿越,使用Callback异步回调。
1032
1033> **说明:**
1034>
1035> 从API version 10开始不在维护。建议使用[cooperate.deactivateCooperate](#cooperatedeactivatecooperate11)替代
1036
1037**系统能力**:SystemCapability.Msdp.DeviceStatus.Cooperate
1038
1039**参数**:
1040
1041| 参数名                | 类型                          | 必填  | 说明                            |
1042| --------             | ---------------------------- | ----  | ----------------------------   |
1043| isUnchained | boolean | 是 | 是否关闭跨设备链路。<br> ture表示关闭跨设备链路,false表示不关闭。 |
1044| callback     | AsyncCallback&lt;void&gt; |  是   | 回调函数,键鼠穿越停止成功时,err为undefined,否则为错误对象。|
1045
1046**错误码:**
1047
1048以下错误码的详细介绍请参见[ohos.devicestatus错误码](errorcode-devicestatus.md)。
1049
1050| 错误码ID | 错误信息          |
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**示例**:
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
1076停止键鼠穿越,使用Promise异步回调。
1077
1078> **说明:**
1079>
1080> 从API version 10开始不在维护。建议使用[cooperate.deactivateCooperate](#cooperatedeactivatecooperate11-1)替代
1081
1082**系统能力**:SystemCapability.Msdp.DeviceStatus.Cooperate
1083
1084**参数**:
1085
1086| 参数名      | 类型    | 必填 | 说明               |
1087| ----------- | ------- | ---- | ------------------ |
1088| isUnchained | boolean | 是   | 是否关闭跨设备链路。<br> ture表示关闭跨设备链路,false表示不关闭。 |
1089
1090
1091
1092**返回值**:
1093
1094| 参数名                | 说明                            |
1095| --------             | ----------------------------   |
1096| Promise&lt;void&gt; |  无返回结果的Promise对象。      |
1097
1098**错误码:**
1099
1100以下错误码的详细介绍请参见[ohos.devicestatus错误码](errorcode-devicestatus.md)。
1101
1102| 错误码ID | 错误信息          |
1103| -------- | ----------------- |
1104| 202 | Not system application. |
1105
1106**示例**:
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
1127获取目标设备键鼠穿越开关的状态,使用Callback异步回调。
1128
1129> **说明:**
1130>
1131> 从API version 10开始不在维护。建议使用[cooperate.getCooperateSwitchState](#cooperategetcooperateswitchstate11)替代
1132
1133**系统能力**:SystemCapability.Msdp.DeviceStatus.Cooperate
1134
1135**参数**:
1136
1137| 参数名                | 类型                          | 必填   | 说明                            |
1138| --------             | ---------                    | ----  | ----------------------------    |
1139| networkId | string                       |  是    | 键鼠穿越目标设备描述符。             |
1140| callback             | AsyncCallback&lt;boolean&gt; |  是    | 回调函数,返回ture表示目标设备键鼠穿越的开关开启,返回false表示开关未开启。 |
1141
1142**错误码:**
1143
1144以下错误码的详细介绍请参见[ohos.devicestatus错误码](errorcode-devicestatus.md)。
1145
1146| 错误码ID | 错误信息          |
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**示例**:
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
1173获取目标设备键鼠穿越开关的状态,使用Promise异步方式返回结果。
1174
1175> **说明:**
1176>
1177> 从API version 10开始不在维护。建议使用[cooperate.getCooperateSwitchState](#cooperategetcooperateswitchstate11-1)替代
1178
1179**系统能力**:SystemCapability.Msdp.DeviceStatus.Cooperate
1180
1181**参数**:
1182
1183| 参数名    | 类型   | 必填   | 说明                            |
1184| --------   | ---------  | ----  | ----------------------------    |
1185| networkId | string     |  是    | 键鼠穿越目标设备描述符。            |
1186
1187**错误码:**
1188
1189以下错误码的详细介绍请参见[ohos.devicestatus错误码](errorcode-devicestatus.md)。
1190
1191| 错误码ID | 错误信息          |
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**返回值**:
1197
1198| 参数                        | 说明                     |
1199| -------------------        | ------------------------------- |
1200| Promise&lt;boolean&gt; | Promise对象,返回ture表示目标设备键鼠穿越的开关开启,返回false表示开关未开启。 |
1201
1202
1203
1204**示例**:
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
1226注册监听键鼠穿越状态。
1227
1228> **说明:**
1229>
1230> 从API version 10开始不在维护。建议使用[on('cooperateMessage')](#oncooperatemessage11)替代
1231
1232**系统能力**:SystemCapability.Msdp.DeviceStatus.Cooperate
1233
1234**参数**:
1235
1236| 参数名                | 类型                                                             | 必填 | 说明                            |
1237| --------             | ----------------------------                                    | ---- | ----------------------------   |
1238| type                 | string                                                          |  是  | 监听类型,取值为'cooperate' |
1239| callback             | Callback&lt;{ networkId: string, msg: [CooperateMsg](#cooperatemsgdeprecated) }&gt; |  是  | 回调函数,异步返回键鼠穿越状态消息。 |
1240
1241**错误码:**
1242
1243以下错误码的详细介绍请参见[ohos.devicestatus错误码](errorcode-devicestatus.md)。
1244
1245| 错误码ID | 错误信息          |
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**示例**:
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
1270取消监听键鼠穿越状态。
1271
1272> **说明:**
1273>
1274> 从API version 10开始不在维护。建议使用[off('cooperateMessage')](#offcooperatemessage11)替代
1275
1276**系统能力**:SystemCapability.Msdp.DeviceStatus.Cooperate
1277
1278**参数**:
1279
1280| 参数名                | 类型                                                              | 必填    | 说明                           |
1281| --------             | ----------------------------                                     | ----   | ----------------------------   |
1282| type                 | string                                                           |  是    | 监听类型,取值为'cooperate'。 |
1283| callback             | AsyncCallback&lt;void&gt; |  否  | 需要取消注册的回调函数,若无此参数,则取消当前应用注册的所有回调函数。 |
1284
1285**错误码:**
1286
1287以下错误码的详细介绍请参见[ohos.devicestatus错误码](errorcode-devicestatus.md)。
1288
1289| 错误码ID | 错误信息          |
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**示例**:
1295
1296```ts
1297// 取消注册单个回调函数
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// 取消注册所有回调函数
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
1331键鼠穿越的消息通知。
1332
1333> **说明:**
1334>
1335> 从API version 10开始不在维护。建议使用[CooperateMessage](#cooperatemessage11)替代
1336
1337**系统能力**:SystemCapability.Msdp.DeviceStatus.Cooperate
1338
1339| 名称                       | 值                             | 说明                              |
1340| --------                     |  -----------------               |  -----------------               |
1341| COOPERATE_PREPARE |  0    |  表示准备键鼠穿越。   |
1342| COOPERATE_UNPREPARE |  1  |  表示取消键鼠穿越准备。  |
1343| COOPERATE_ACTIVATE |  2   |  表示启动键鼠穿越。  |
1344| COOPERATE_ACTIVATE_SUCCESS | 3 | 表示键鼠穿越启动成功。 |
1345| COOPERATE_ACTIVATE_FAIL | 4 | 表示键鼠穿越启动失败。 |
1346| COOPERATE_DEACTIVATE_SUCCESS | 5 | 表示键鼠穿越停止成功。 |
1347| COOPERATE_DEACTIVATE_FAIL | 6 | 表示键鼠穿越停止失败。 |
1348| COOPERATE_SESSION_DISCONNECTED | 7 | 表示键鼠穿越会话断开。 |
1349