1e41f4b71Sopenharmony_ci# @ohos.multimodalInput.inputDeviceCooperate (Screen Hopping) (System API)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **inputDeviceCooperate** module implements screen hopping for two or more networked devices to share the keyboard and mouse for collaborative operations.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci>- The APIs provided by this module are no longer maintained since API Version 10. You are advised to use [@ohos.cooperate (Screen Hopping)](../apis-distributedservice-kit/js-apis-devicestatus-cooperate-sys.md).
8e41f4b71Sopenharmony_ci> 
9e41f4b71Sopenharmony_ci>- The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
10e41f4b71Sopenharmony_ci>
11e41f4b71Sopenharmony_ci>- The APIs provided by this module are system APIs.
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci## Modules to Import
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci```ts
16e41f4b71Sopenharmony_ciimport { inputDeviceCooperate } from '@kit.InputKit';
17e41f4b71Sopenharmony_ci```
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci## inputDeviceCooperate.enable
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_cienable(enable: boolean, callback: AsyncCallback<void>): void
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ciSpecifies whether to enable screen hopping. This API uses an asynchronous callback to return the result.
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MultimodalInput.Input.Cooperator
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci**Parameters**
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci| Name   | Type     | Mandatory | Description   |
30e41f4b71Sopenharmony_ci| -------- | ------------------------- | ---- | --------------------------- |
31e41f4b71Sopenharmony_ci| enable   | boolean                   | Yes  | Whether to enable screen hopping.|
32e41f4b71Sopenharmony_ci| callback | AsyncCallback<void>  | Yes |Callback used to return the result.  |
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_ci**Error codes**
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ciFor details about the following error codes, see [Screen Hopping Error Codes](../apis-distributedservice-kit/errorcode-devicestatus.md).
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci| ID| Error Message         |
39e41f4b71Sopenharmony_ci| -------- | -----------------|
40e41f4b71Sopenharmony_ci| 401 | Parameter error.      |
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ci**Example**
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci```ts
46e41f4b71Sopenharmony_ciimport { inputDeviceCooperate } from '@kit.InputKit';
47e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_citry {
50e41f4b71Sopenharmony_ci  inputDeviceCooperate.enable(true, (error: BusinessError) => {
51e41f4b71Sopenharmony_ci    if (error) {
52e41f4b71Sopenharmony_ci      console.log(`Keyboard mouse crossing enable failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
53e41f4b71Sopenharmony_ci      return;
54e41f4b71Sopenharmony_ci    }
55e41f4b71Sopenharmony_ci    console.log(`Keyboard mouse crossing enable success.`);
56e41f4b71Sopenharmony_ci  });
57e41f4b71Sopenharmony_ci} catch (error) {
58e41f4b71Sopenharmony_ci  console.log(`Keyboard mouse crossing enable failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
59e41f4b71Sopenharmony_ci}
60e41f4b71Sopenharmony_ci```
61e41f4b71Sopenharmony_ci
62e41f4b71Sopenharmony_ci## inputDeviceCooperate.enable
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_cienable(enable: boolean): Promise<void>
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_ciSpecifies whether to enable screen hopping. This API uses a promise to return the result.
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ci
69e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MultimodalInput.Input.Cooperator
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ci**Parameters**
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ci| Name    | Type    | Mandatory | Description                                                                                |
74e41f4b71Sopenharmony_ci| --------- | ------- | ---- | -------------------------------------------------------------------                 |
75e41f4b71Sopenharmony_ci| enable    | boolean | Yes  | Whether to enable screen hopping.                  |
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ci**Return value**
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_ci| Parameters                | Description                    |
80e41f4b71Sopenharmony_ci| ------------------- | ------------------------------- |
81e41f4b71Sopenharmony_ci| Promise<void>      | Promise used to return the result.       |
82e41f4b71Sopenharmony_ci
83e41f4b71Sopenharmony_ci**Error codes**
84e41f4b71Sopenharmony_ci
85e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
86e41f4b71Sopenharmony_ci
87e41f4b71Sopenharmony_ci| ID| Error Message         |
88e41f4b71Sopenharmony_ci| -------- | -----------------|
89e41f4b71Sopenharmony_ci| 401 | Parameter error.      |
90e41f4b71Sopenharmony_ci
91e41f4b71Sopenharmony_ci**Example**
92e41f4b71Sopenharmony_ci
93e41f4b71Sopenharmony_ci```ts
94e41f4b71Sopenharmony_ciimport { inputDeviceCooperate } from '@kit.InputKit';
95e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
96e41f4b71Sopenharmony_ci
97e41f4b71Sopenharmony_citry {
98e41f4b71Sopenharmony_ci  inputDeviceCooperate.enable(true).then(() => {
99e41f4b71Sopenharmony_ci    console.log(`Keyboard mouse crossing enable success.`);
100e41f4b71Sopenharmony_ci  }, (error: BusinessError) => {
101e41f4b71Sopenharmony_ci    console.log(`Keyboard mouse crossing enable failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
102e41f4b71Sopenharmony_ci  });
103e41f4b71Sopenharmony_ci} catch (error) {
104e41f4b71Sopenharmony_ci  console.log(`Keyboard mouse crossing enable failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
105e41f4b71Sopenharmony_ci}
106e41f4b71Sopenharmony_ci```
107e41f4b71Sopenharmony_ci
108e41f4b71Sopenharmony_ci## inputDeviceCooperate.start
109e41f4b71Sopenharmony_ci
110e41f4b71Sopenharmony_cistart(sinkDeviceDescriptor: string, srcInputDeviceId: number, callback: AsyncCallback\<void>): void
111e41f4b71Sopenharmony_ci
112e41f4b71Sopenharmony_ciStarts screen hopping. This API uses an asynchronous callback to return the result.
113e41f4b71Sopenharmony_ci
114e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MultimodalInput.Input.Cooperator
115e41f4b71Sopenharmony_ci
116e41f4b71Sopenharmony_ci**Parameters**
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_ci| Name               | Type                         | Mandatory | Description                           |
119e41f4b71Sopenharmony_ci| --------             | ---------------------------- | ----  | ----------------------------   |
120e41f4b71Sopenharmony_ci| sinkDeviceDescriptor | string                       |  Yes  | Descriptor of the target device for screen hopping.            |
121e41f4b71Sopenharmony_ci| srcInputDeviceId     | number                       |  Yes  | ID of the target device for screen hopping.          |
122e41f4b71Sopenharmony_ci| callback             | AsyncCallback\<void>         |  Yes   | Callback used to return the result.|
123e41f4b71Sopenharmony_ci
124e41f4b71Sopenharmony_ci**Error codes**
125e41f4b71Sopenharmony_ci
126e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Screen Hopping Error Codes](errorcode-multimodalinput.md).
127e41f4b71Sopenharmony_ci
128e41f4b71Sopenharmony_ci| ID| Error Message|
129e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
130e41f4b71Sopenharmony_ci| 401      | Parameter error.    |
131e41f4b71Sopenharmony_ci| 4400001  | Incorrect descriptor for the target device.                |
132e41f4b71Sopenharmony_ci| 4400002  | Screen hop failed.    |
133e41f4b71Sopenharmony_ci
134e41f4b71Sopenharmony_ci**Example**
135e41f4b71Sopenharmony_ci
136e41f4b71Sopenharmony_ci```ts
137e41f4b71Sopenharmony_ciimport { inputDeviceCooperate } from '@kit.InputKit';
138e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
139e41f4b71Sopenharmony_ci
140e41f4b71Sopenharmony_cilet sinkDeviceDescriptor = "descriptor";
141e41f4b71Sopenharmony_cilet srcInputDeviceId = 0;
142e41f4b71Sopenharmony_citry {
143e41f4b71Sopenharmony_ci  inputDeviceCooperate.start(sinkDeviceDescriptor, srcInputDeviceId, (error: BusinessError) => {
144e41f4b71Sopenharmony_ci    if (error) {
145e41f4b71Sopenharmony_ci      console.log(`Start Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
146e41f4b71Sopenharmony_ci      return;
147e41f4b71Sopenharmony_ci    }
148e41f4b71Sopenharmony_ci    console.log(`Start Keyboard mouse crossing success.`);
149e41f4b71Sopenharmony_ci  });
150e41f4b71Sopenharmony_ci} catch (error) {
151e41f4b71Sopenharmony_ci  console.log(`Start Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
152e41f4b71Sopenharmony_ci}
153e41f4b71Sopenharmony_ci```
154e41f4b71Sopenharmony_ci
155e41f4b71Sopenharmony_ci## inputDeviceCooperate.start
156e41f4b71Sopenharmony_ci
157e41f4b71Sopenharmony_cistart(sinkDeviceDescriptor: string, srcInputDeviceId: number): Promise\<void>
158e41f4b71Sopenharmony_ci
159e41f4b71Sopenharmony_ciStarts screen hopping. This API uses a promise to return the result.
160e41f4b71Sopenharmony_ci
161e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MultimodalInput.Input.Cooperator
162e41f4b71Sopenharmony_ci
163e41f4b71Sopenharmony_ci**Parameters**
164e41f4b71Sopenharmony_ci
165e41f4b71Sopenharmony_ci| Name               | Type                         | Mandatory | Description                           |
166e41f4b71Sopenharmony_ci| --------             | ---------------------------- | ----  | ----------------------------   |
167e41f4b71Sopenharmony_ci| sinkDeviceDescriptor | string                       |  Yes  | Descriptor of the target device for screen hopping.            |
168e41f4b71Sopenharmony_ci| srcInputDeviceId     | number                       |  Yes  | ID of the target device for screen hopping.          |
169e41f4b71Sopenharmony_ci
170e41f4b71Sopenharmony_ci
171e41f4b71Sopenharmony_ci
172e41f4b71Sopenharmony_ci**Return value**
173e41f4b71Sopenharmony_ci
174e41f4b71Sopenharmony_ci| Name                 | Description                            |
175e41f4b71Sopenharmony_ci| ---------------------- | ------------------------------- |
176e41f4b71Sopenharmony_ci| Promise\<void>         | Promise used to return the result.      |
177e41f4b71Sopenharmony_ci
178e41f4b71Sopenharmony_ci**Error codes**
179e41f4b71Sopenharmony_ci
180e41f4b71Sopenharmony_ciFor details about the error codes, see [Screen Hopping Error Codes](errorcode-multimodalinput.md).
181e41f4b71Sopenharmony_ci
182e41f4b71Sopenharmony_ci| ID| Error Message|
183e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
184e41f4b71Sopenharmony_ci| 401      | Parameter error.    |
185e41f4b71Sopenharmony_ci| 4400001  | Incorrect descriptor for the target device.          |
186e41f4b71Sopenharmony_ci| 4400002  | Screen hop failed.               |
187e41f4b71Sopenharmony_ci
188e41f4b71Sopenharmony_ci**Example**
189e41f4b71Sopenharmony_ci
190e41f4b71Sopenharmony_ci```ts
191e41f4b71Sopenharmony_ciimport { inputDeviceCooperate } from '@kit.InputKit';
192e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
193e41f4b71Sopenharmony_ci
194e41f4b71Sopenharmony_cilet sinkDeviceDescriptor = "descriptor";
195e41f4b71Sopenharmony_cilet srcInputDeviceId = 0;
196e41f4b71Sopenharmony_citry {
197e41f4b71Sopenharmony_ci  inputDeviceCooperate.start(sinkDeviceDescriptor, srcInputDeviceId).then(() => {
198e41f4b71Sopenharmony_ci    console.log(`Start Keyboard mouse crossing success.`);
199e41f4b71Sopenharmony_ci  }, (error: BusinessError) => {
200e41f4b71Sopenharmony_ci    console.log(`Start Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
201e41f4b71Sopenharmony_ci  });
202e41f4b71Sopenharmony_ci} catch (error) {
203e41f4b71Sopenharmony_ci  console.log(`Start Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
204e41f4b71Sopenharmony_ci}
205e41f4b71Sopenharmony_ci```
206e41f4b71Sopenharmony_ci
207e41f4b71Sopenharmony_ci## inputDeviceCooperate.stop
208e41f4b71Sopenharmony_ci
209e41f4b71Sopenharmony_cistop(callback: AsyncCallback\<void>): void
210e41f4b71Sopenharmony_ci
211e41f4b71Sopenharmony_ciStops screen hopping. This API uses an asynchronous callback to return the result.
212e41f4b71Sopenharmony_ci
213e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MultimodalInput.Input.Cooperator
214e41f4b71Sopenharmony_ci
215e41f4b71Sopenharmony_ci**Parameters**
216e41f4b71Sopenharmony_ci
217e41f4b71Sopenharmony_ci| Name               | Type                         | Mandatory | Description                           |
218e41f4b71Sopenharmony_ci| --------             | ---------------------------- | ----  | ----------------------------   |
219e41f4b71Sopenharmony_ci| callback             | AsyncCallback\<void>         |  Yes  | Callback used to return the result.       |
220e41f4b71Sopenharmony_ci
221e41f4b71Sopenharmony_ci**Error codes**
222e41f4b71Sopenharmony_ci
223e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
224e41f4b71Sopenharmony_ci
225e41f4b71Sopenharmony_ci| ID| Error Message          |
226e41f4b71Sopenharmony_ci| -------- | ----------------- |
227e41f4b71Sopenharmony_ci| 401      | Parameter error.  |
228e41f4b71Sopenharmony_ci
229e41f4b71Sopenharmony_ci**Example**
230e41f4b71Sopenharmony_ci
231e41f4b71Sopenharmony_ci```ts
232e41f4b71Sopenharmony_ciimport { inputDeviceCooperate } from '@kit.InputKit';
233e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
234e41f4b71Sopenharmony_ci
235e41f4b71Sopenharmony_citry {
236e41f4b71Sopenharmony_ci  inputDeviceCooperate.stop((error: BusinessError) => {
237e41f4b71Sopenharmony_ci    if (error) {
238e41f4b71Sopenharmony_ci      console.log(`Stop Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
239e41f4b71Sopenharmony_ci      return;
240e41f4b71Sopenharmony_ci    }
241e41f4b71Sopenharmony_ci    console.log(`Stop Keyboard mouse crossing success.`);
242e41f4b71Sopenharmony_ci  });
243e41f4b71Sopenharmony_ci} catch (error) {
244e41f4b71Sopenharmony_ci  console.log(`Stop Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
245e41f4b71Sopenharmony_ci}
246e41f4b71Sopenharmony_ci```
247e41f4b71Sopenharmony_ci
248e41f4b71Sopenharmony_ci## inputDeviceCooperate.stop
249e41f4b71Sopenharmony_ci
250e41f4b71Sopenharmony_cistop(): Promise\<void>
251e41f4b71Sopenharmony_ci
252e41f4b71Sopenharmony_ciStops screen hopping. This API uses a promise to return the result.
253e41f4b71Sopenharmony_ci
254e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MultimodalInput.Input.Cooperator
255e41f4b71Sopenharmony_ci
256e41f4b71Sopenharmony_ci**Return value**
257e41f4b71Sopenharmony_ci
258e41f4b71Sopenharmony_ci| Name               | Description                           |
259e41f4b71Sopenharmony_ci| --------             | ----------------------------   |
260e41f4b71Sopenharmony_ci| Promise\<void>       |  Promise used to return the result.     |
261e41f4b71Sopenharmony_ci
262e41f4b71Sopenharmony_ci**Example**
263e41f4b71Sopenharmony_ci
264e41f4b71Sopenharmony_ci```ts
265e41f4b71Sopenharmony_ciimport { inputDeviceCooperate } from '@kit.InputKit';
266e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
267e41f4b71Sopenharmony_ci
268e41f4b71Sopenharmony_citry {
269e41f4b71Sopenharmony_ci  inputDeviceCooperate.stop().then(() => {
270e41f4b71Sopenharmony_ci    console.log(`Stop Keyboard mouse crossing success.`);
271e41f4b71Sopenharmony_ci  }, (error: BusinessError) => {
272e41f4b71Sopenharmony_ci    console.log(`Stop Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
273e41f4b71Sopenharmony_ci  });
274e41f4b71Sopenharmony_ci} catch (error) {
275e41f4b71Sopenharmony_ci  console.log(`Stop Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
276e41f4b71Sopenharmony_ci}
277e41f4b71Sopenharmony_ci```
278e41f4b71Sopenharmony_ci
279e41f4b71Sopenharmony_ci## inputDeviceCooperate.getState
280e41f4b71Sopenharmony_ci
281e41f4b71Sopenharmony_cigetState(deviceDescriptor: string, callback: AsyncCallback<{ state: boolean }>): void
282e41f4b71Sopenharmony_ci
283e41f4b71Sopenharmony_ciChecks whether screen hopping is enabled. This API uses an asynchronous callback to return the result.
284e41f4b71Sopenharmony_ci
285e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MultimodalInput.Input.Cooperator
286e41f4b71Sopenharmony_ci
287e41f4b71Sopenharmony_ci**Parameters**
288e41f4b71Sopenharmony_ci
289e41f4b71Sopenharmony_ci| Name               | Type                         | Mandatory  | Description                           |
290e41f4b71Sopenharmony_ci| --------             | ---------                    | ----  | ----------------------------    |
291e41f4b71Sopenharmony_ci| deviceDescriptor     | string                       |  Yes   | Descriptor of the target device for screen hopping.            |
292e41f4b71Sopenharmony_ci| callback             | AsyncCallback<{ state: boolean }> |  Yes   | Callback used to return the result.       |
293e41f4b71Sopenharmony_ci
294e41f4b71Sopenharmony_ci**Error codes**
295e41f4b71Sopenharmony_ci
296e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
297e41f4b71Sopenharmony_ci
298e41f4b71Sopenharmony_ci| ID| Error Message         |
299e41f4b71Sopenharmony_ci| -------- | ----------------- |
300e41f4b71Sopenharmony_ci| 401      | Parameter error.  |
301e41f4b71Sopenharmony_ci
302e41f4b71Sopenharmony_ci
303e41f4b71Sopenharmony_ci**Example**
304e41f4b71Sopenharmony_ci
305e41f4b71Sopenharmony_ci```ts
306e41f4b71Sopenharmony_ciimport { inputDeviceCooperate } from '@kit.InputKit';
307e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
308e41f4b71Sopenharmony_ci
309e41f4b71Sopenharmony_cilet deviceDescriptor = "descriptor";
310e41f4b71Sopenharmony_citry {
311e41f4b71Sopenharmony_ci  inputDeviceCooperate.getState(deviceDescriptor, (error: BusinessError, data: object) => {
312e41f4b71Sopenharmony_ci    if (error) {
313e41f4b71Sopenharmony_ci      console.log(`Get the status failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
314e41f4b71Sopenharmony_ci      return;
315e41f4b71Sopenharmony_ci    }
316e41f4b71Sopenharmony_ci    console.log(`Get the status success, data: ${JSON.stringify(data)}`);
317e41f4b71Sopenharmony_ci  });
318e41f4b71Sopenharmony_ci} catch (error) {
319e41f4b71Sopenharmony_ci  console.log(`Get the status failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
320e41f4b71Sopenharmony_ci}
321e41f4b71Sopenharmony_ci```
322e41f4b71Sopenharmony_ci
323e41f4b71Sopenharmony_ci## inputDeviceCooperate.getState
324e41f4b71Sopenharmony_ci
325e41f4b71Sopenharmony_cigetState(deviceDescriptor: string): Promise<{ state: boolean }>
326e41f4b71Sopenharmony_ci
327e41f4b71Sopenharmony_ciChecks whether screen hopping is enabled. This API uses a promise to return the result.
328e41f4b71Sopenharmony_ci
329e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MultimodalInput.Input.Cooperator
330e41f4b71Sopenharmony_ci
331e41f4b71Sopenharmony_ci**Parameters**
332e41f4b71Sopenharmony_ci
333e41f4b71Sopenharmony_ci| Name               | Type                         | Mandatory  | Description                           |
334e41f4b71Sopenharmony_ci| --------             | ---------                    | ----  | ----------------------------    |
335e41f4b71Sopenharmony_ci| deviceDescriptor     | string                       |  Yes   | Descriptor of the target device for screen hopping.           |
336e41f4b71Sopenharmony_ci
337e41f4b71Sopenharmony_ci**Return value**
338e41f4b71Sopenharmony_ci
339e41f4b71Sopenharmony_ci| Parameters                       | Description                    |
340e41f4b71Sopenharmony_ci| -------------------        | ------------------------------- |
341e41f4b71Sopenharmony_ci| Promise<{ state: boolean }>| Promise used to return the result.       |
342e41f4b71Sopenharmony_ci
343e41f4b71Sopenharmony_ci**Error codes**
344e41f4b71Sopenharmony_ci
345e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
346e41f4b71Sopenharmony_ci
347e41f4b71Sopenharmony_ci| ID| Error Message         |
348e41f4b71Sopenharmony_ci| -------- | ----------------- |
349e41f4b71Sopenharmony_ci| 401      | Parameter error.  |
350e41f4b71Sopenharmony_ci
351e41f4b71Sopenharmony_ci
352e41f4b71Sopenharmony_ci**Example**
353e41f4b71Sopenharmony_ci
354e41f4b71Sopenharmony_ci```ts
355e41f4b71Sopenharmony_ciimport { inputDeviceCooperate } from '@kit.InputKit';
356e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
357e41f4b71Sopenharmony_ci
358e41f4b71Sopenharmony_cilet deviceDescriptor = "descriptor";
359e41f4b71Sopenharmony_citry {
360e41f4b71Sopenharmony_ci  inputDeviceCooperate.getState(deviceDescriptor).then((data: object) => {
361e41f4b71Sopenharmony_ci    console.log(`Get the status success, data: ${JSON.stringify(data)}`);
362e41f4b71Sopenharmony_ci  }, (error: BusinessError) => {
363e41f4b71Sopenharmony_ci    console.log(`Get the status failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
364e41f4b71Sopenharmony_ci  });
365e41f4b71Sopenharmony_ci} catch (error) {
366e41f4b71Sopenharmony_ci  console.log(`Get the status failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
367e41f4b71Sopenharmony_ci}
368e41f4b71Sopenharmony_ci```
369e41f4b71Sopenharmony_ci
370e41f4b71Sopenharmony_ci## on('cooperation')
371e41f4b71Sopenharmony_ci
372e41f4b71Sopenharmony_cion(type: 'cooperation', callback: AsyncCallback<{ deviceDescriptor: string, eventMsg: EventMsg }>): void
373e41f4b71Sopenharmony_ci
374e41f4b71Sopenharmony_ciEnables listening for screen hopping status change events.
375e41f4b71Sopenharmony_ci
376e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MultimodalInput.Input.Cooperator
377e41f4b71Sopenharmony_ci
378e41f4b71Sopenharmony_ci**Parameters**
379e41f4b71Sopenharmony_ci
380e41f4b71Sopenharmony_ci| Name               | Type                                                            | Mandatory| Description                           |
381e41f4b71Sopenharmony_ci| --------             | ----------------------------                                    | ---- | ----------------------------   |
382e41f4b71Sopenharmony_ci| type                 | string                                                          |  Yes | Event type. The value is **cooperation**.        |
383e41f4b71Sopenharmony_ci| callback             | AsyncCallback<{ deviceDescriptor: string, eventMsg: [EventMsg](#eventmsg) }> |  Yes | Callback used to return the result.   |
384e41f4b71Sopenharmony_ci
385e41f4b71Sopenharmony_ci**Error codes**
386e41f4b71Sopenharmony_ci
387e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
388e41f4b71Sopenharmony_ci
389e41f4b71Sopenharmony_ci| ID| Error Message         |
390e41f4b71Sopenharmony_ci| -------- | ----------------- |
391e41f4b71Sopenharmony_ci| 401      | Parameter error.  |
392e41f4b71Sopenharmony_ci
393e41f4b71Sopenharmony_ci
394e41f4b71Sopenharmony_ci**Example**
395e41f4b71Sopenharmony_ci
396e41f4b71Sopenharmony_ci```ts
397e41f4b71Sopenharmony_ciimport { inputDeviceCooperate } from '@kit.InputKit';
398e41f4b71Sopenharmony_ci
399e41f4b71Sopenharmony_cifunction callback(msg: object) {
400e41f4b71Sopenharmony_ci  console.log(`Keyboard mouse crossing event: ${JSON.stringify(msg)}`);
401e41f4b71Sopenharmony_ci  return false;
402e41f4b71Sopenharmony_ci}
403e41f4b71Sopenharmony_citry {
404e41f4b71Sopenharmony_ci  inputDeviceCooperate.on('cooperation', callback);
405e41f4b71Sopenharmony_ci} catch (error) {
406e41f4b71Sopenharmony_ci  console.log(`Register failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
407e41f4b71Sopenharmony_ci}
408e41f4b71Sopenharmony_ci```
409e41f4b71Sopenharmony_ci
410e41f4b71Sopenharmony_ci## off('cooperation')
411e41f4b71Sopenharmony_ci
412e41f4b71Sopenharmony_cioff(type: 'cooperation', callback?: AsyncCallback\<void>): void
413e41f4b71Sopenharmony_ci
414e41f4b71Sopenharmony_ciDisables listening for screen hopping status change events.
415e41f4b71Sopenharmony_ci
416e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MultimodalInput.Input.Cooperator
417e41f4b71Sopenharmony_ci
418e41f4b71Sopenharmony_ci**Parameters**
419e41f4b71Sopenharmony_ci
420e41f4b71Sopenharmony_ci| Name               | Type                                                             | Mandatory   | Description                          |
421e41f4b71Sopenharmony_ci| --------             | ----------------------------                                     | ----   | ----------------------------   |
422e41f4b71Sopenharmony_ci| type                 | string                                                           |  Yes   | Event type. The value is **cooperation**.        |
423e41f4b71Sopenharmony_ci| callback             | AsyncCallback\<void> |  No | Callback to be unregistered. If this parameter is not specified, all callbacks registered by the current application will be unregistered.|
424e41f4b71Sopenharmony_ci
425e41f4b71Sopenharmony_ci**Error codes**
426e41f4b71Sopenharmony_ci
427e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
428e41f4b71Sopenharmony_ci
429e41f4b71Sopenharmony_ci| ID| Error Message         |
430e41f4b71Sopenharmony_ci| -------- | ----------------- |
431e41f4b71Sopenharmony_ci| 401      | Parameter error.  |
432e41f4b71Sopenharmony_ci
433e41f4b71Sopenharmony_ci
434e41f4b71Sopenharmony_ci**Example**
435e41f4b71Sopenharmony_ci
436e41f4b71Sopenharmony_ci```ts
437e41f4b71Sopenharmony_ciimport { inputDeviceCooperate } from '@kit.InputKit';
438e41f4b71Sopenharmony_ci
439e41f4b71Sopenharmony_ci// Unregister a single callback.
440e41f4b71Sopenharmony_cifunction callbackOn(msg: object) {
441e41f4b71Sopenharmony_ci  console.log(`Keyboard mouse crossing event: ${JSON.stringify(msg)}`);
442e41f4b71Sopenharmony_ci  return false;
443e41f4b71Sopenharmony_ci}
444e41f4b71Sopenharmony_cifunction callbackOff() {
445e41f4b71Sopenharmony_ci  console.log(`Keyboard mouse crossing event`);
446e41f4b71Sopenharmony_ci  return false;
447e41f4b71Sopenharmony_ci}
448e41f4b71Sopenharmony_citry {
449e41f4b71Sopenharmony_ci  inputDeviceCooperate.on('cooperation', callbackOn);
450e41f4b71Sopenharmony_ci  inputDeviceCooperate.off("cooperation", callbackOff);
451e41f4b71Sopenharmony_ci} catch (error) {
452e41f4b71Sopenharmony_ci  console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
453e41f4b71Sopenharmony_ci}
454e41f4b71Sopenharmony_ci```
455e41f4b71Sopenharmony_ci```ts
456e41f4b71Sopenharmony_ciimport { inputDeviceCooperate } from '@kit.InputKit';
457e41f4b71Sopenharmony_ci
458e41f4b71Sopenharmony_ci// Unregister all callbacks.
459e41f4b71Sopenharmony_cifunction callback(msg: object) {
460e41f4b71Sopenharmony_ci  console.log(`Keyboard mouse crossing event: ${JSON.stringify(msg)}`);
461e41f4b71Sopenharmony_ci  return false;
462e41f4b71Sopenharmony_ci}
463e41f4b71Sopenharmony_citry {
464e41f4b71Sopenharmony_ci  inputDeviceCooperate.on('cooperation', callback);
465e41f4b71Sopenharmony_ci  inputDeviceCooperate.off("cooperation");
466e41f4b71Sopenharmony_ci} catch (error) {
467e41f4b71Sopenharmony_ci  console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
468e41f4b71Sopenharmony_ci}
469e41f4b71Sopenharmony_ci```
470e41f4b71Sopenharmony_ci
471e41f4b71Sopenharmony_ci## EventMsg
472e41f4b71Sopenharmony_ci
473e41f4b71Sopenharmony_ciEnumerates screen hopping event.
474e41f4b71Sopenharmony_ci
475e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MultimodalInput.Input.Cooperator
476e41f4b71Sopenharmony_ci
477e41f4b71Sopenharmony_ci| Name                      | Value       | Description                             |
478e41f4b71Sopenharmony_ci| --------                     | --------- |  -----------------               |
479e41f4b71Sopenharmony_ci| MSG_COOPERATE_INFO_START     | 200       |  Screen hopping starts.      |
480e41f4b71Sopenharmony_ci| MSG_COOPERATE_INFO_SUCCESS   | 201       |  Screen hopping succeeds.     |
481e41f4b71Sopenharmony_ci| MSG_COOPERATE_INFO_FAIL      | 202       |  Screen hopping fails.     |
482e41f4b71Sopenharmony_ci| MSG_COOPERATE_STATE_ON       | 500       |  Screen hopping is enabled.  |
483e41f4b71Sopenharmony_ci| MSG_COOPERATE_STATE_OFF      | 501       |  Screen hopping is disabled.  |
484