harmony 鸿蒙@ohos.multimodalInput.inputDeviceCooperate (Screen Hopping) (To Be Deprecated Soon)
@ohos.multimodalInput.inputDeviceCooperate (Screen Hopping) (To Be Deprecated Soon)
The inputDeviceCooperate module implements screen hopping for two or more networked devices to share the keyboard and mouse for collaborative operations.
NOTE
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.
The APIs provided by this module are system APIs.
Modules to Import
import inputDeviceCooperate from '@ohos.multimodalInput.inputDeviceCooperate'
inputDeviceCooperate.enable
enable(enable: boolean, callback: AsyncCallback<void>): void
Specifies whether to enable screen hopping. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.MultimodalInput.Input.Cooperator
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
enable | boolean | Yes | Whether to enable screen hopping. |
callback | AsyncCallback<void> | Yes | Callback used to return the result. |
Example
import inputDeviceCooperate from '@ohos.multimodalInput.inputDeviceCooperate'
import { BusinessError } from '@ohos.base'
try {
inputDeviceCooperate.enable(true, (error: BusinessError) => {
if (error) {
console.log(`Keyboard mouse crossing enable failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
return;
}
console.log(`Keyboard mouse crossing enable success.`);
});
} catch (error) {
console.log(`Keyboard mouse crossing enable failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
inputDeviceCooperate.enable
enable(enable: boolean): Promise<void>
Specifies whether to enable screen hopping. This API uses a promise to return the result.
System capability: SystemCapability.MultimodalInput.Input.Cooperator
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
enable | boolean | Yes | Whether to enable screen hopping. |
Return value
Parameters | Description |
---|---|
Promise<void> | Promise used to return the result. |
Example
import inputDeviceCooperate from '@ohos.multimodalInput.inputDeviceCooperate'
import { BusinessError } from '@ohos.base'
try {
inputDeviceCooperate.enable(true).then(() => {
console.log(`Keyboard mouse crossing enable success.`);
}, (error: BusinessError) => {
console.log(`Keyboard mouse crossing enable failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
});
} catch (error) {
console.log(`Keyboard mouse crossing enable failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
inputDeviceCooperate.start
start(sinkDeviceDescriptor: string, srcInputDeviceId: number, callback: AsyncCallback<void>): void
Starts screen hopping. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.MultimodalInput.Input.Cooperator
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
sinkDeviceDescriptor | string | Yes | Descriptor of the target device for screen hopping. |
srcInputDeviceId | number | Yes | ID of the target device for screen hopping. |
callback | AsyncCallback<void> | Yes | Callback used to return the result. |
Error codes
For details about the error codes, see Screen Hopping Error Codes.
ID | Error Message |
---|---|
4400001 | Incorrect descriptor for the target device. |
4400002 | Screen hop failed. |
Example
import inputDeviceCooperate from '@ohos.multimodalInput.inputDeviceCooperate'
import { BusinessError } from '@ohos.base'
let sinkDeviceDescriptor = "descriptor";
let srcInputDeviceId = 0;
try {
inputDeviceCooperate.start(sinkDeviceDescriptor, srcInputDeviceId, (error: BusinessError) => {
if (error) {
console.log(`Start Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
return;
}
console.log(`Start Keyboard mouse crossing success.`);
});
} catch (error) {
console.log(`Start Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
inputDeviceCooperate.start
start(sinkDeviceDescriptor: string, srcInputDeviceId: number): Promise<void>
Starts screen hopping. This API uses a promise to return the result.
System capability: SystemCapability.MultimodalInput.Input.Cooperator
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
sinkDeviceDescriptor | string | Yes | Descriptor of the target device for screen hopping. |
srcInputDeviceId | number | Yes | ID of the target device for screen hopping. |
Return value
Name | Description |
---|---|
Promise<void> | Promise used to return the result. |
Error codes
For details about the error codes, see Screen Hopping Error Codes.
ID | Error Message |
---|---|
4400001 | Incorrect descriptor for the target device. |
4400002 | Screen hop failed. |
Example
import inputDeviceCooperate from '@ohos.multimodalInput.inputDeviceCooperate'
import { BusinessError } from '@ohos.base'
let sinkDeviceDescriptor = "descriptor";
let srcInputDeviceId = 0;
try {
inputDeviceCooperate.start(sinkDeviceDescriptor, srcInputDeviceId).then(() => {
console.log(`Start Keyboard mouse crossing success.`);
}, (error: BusinessError) => {
console.log(`Start Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
});
} catch (error) {
console.log(`Start Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
inputDeviceCooperate.stop
stop(callback: AsyncCallback<void>): void
Stops screen hopping. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.MultimodalInput.Input.Cooperator
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
callback | AsyncCallback<void> | Yes | Callback used to return the result. |
Example
import inputDeviceCooperate from '@ohos.multimodalInput.inputDeviceCooperate'
import { BusinessError } from '@ohos.base'
try {
inputDeviceCooperate.stop((error: BusinessError) => {
if (error) {
console.log(`Stop Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
return;
}
console.log(`Stop Keyboard mouse crossing success.`);
});
} catch (error) {
console.log(`Stop Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
inputDeviceCooperate.stop
stop(): Promise<void>
Stops screen hopping. This API uses a promise to return the result.
System capability: SystemCapability.MultimodalInput.Input.Cooperator
Return value
Name | Description |
---|---|
Promise<void> | Promise used to return the result. |
Example
import inputDeviceCooperate from '@ohos.multimodalInput.inputDeviceCooperate'
import { BusinessError } from '@ohos.base'
try {
inputDeviceCooperate.stop().then(() => {
console.log(`Stop Keyboard mouse crossing success.`);
}, (error: BusinessError) => {
console.log(`Stop Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
});
} catch (error) {
console.log(`Stop Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
inputDeviceCooperate.getState
getState(deviceDescriptor: string, callback: AsyncCallback<{ state: boolean }>): void
Checks whether screen hopping is enabled. This API uses an asynchronous callback to return the result.
System capability: SystemCapability.MultimodalInput.Input.Cooperator
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
deviceDescriptor | string | Yes | Descriptor of the target device for screen hopping. |
callback | AsyncCallback<{ state: boolean }> | Yes | Callback used to return the result. |
Example
import inputDeviceCooperate from '@ohos.multimodalInput.inputDeviceCooperate'
import { BusinessError } from '@ohos.base'
let deviceDescriptor = "descriptor";
try {
inputDeviceCooperate.getState(deviceDescriptor, (error: BusinessError, data: boolean) => {
if (error) {
console.log(`Get the status failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
return;
}
console.log(`Get the status success, data: ${JSON.stringify(data)}`);
});
} catch (error) {
console.log(`Get the status failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
inputDeviceCooperate.getState
getState(deviceDescriptor: string): Promise<{ state: boolean }>
Checks whether screen hopping is enabled. This API uses a promise to return the result.
System capability: SystemCapability.MultimodalInput.Input.Cooperator
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
deviceDescriptor | string | Yes | Descriptor of the target device for screen hopping. |
Return value
Parameters | Description |
---|---|
Promise<{ state: boolean }> | Promise used to return the result. |
Example
import inputDeviceCooperate from '@ohos.multimodalInput.inputDeviceCooperate'
import { BusinessError } from '@ohos.base'
let deviceDescriptor = "descriptor";
try {
inputDeviceCooperate.getState(deviceDescriptor).then((data: boolean) => {
console.log(`Get the status success, data: ${JSON.stringify(data)}`);
}, (error: BusinessError) => {
console.log(`Get the status failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
});
} catch (error) {
console.log(`Get the status failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
on(‘cooperation’)
on(type: ‘cooperation’, callback: AsyncCallback<{ deviceDescriptor: string, eventMsg: EventMsg }>): void
Enables listening for screen hopping status change events.
System capability: SystemCapability.MultimodalInput.Input.Cooperator
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is cooperation. |
callback | AsyncCallback<{ deviceDescriptor: string, eventMsg: EventMsg }> | Yes | Callback used to return the result. |
Example
import inputDeviceCooperate from '@ohos.multimodalInput.inputDeviceCooperate'
function callback(deviceDescriptor: string, eventMsg: inputDeviceCooperate.EventMsg) {
console.log(`Keyboard mouse crossing event: ${JSON.stringify(deviceDescriptor)}`);
return false;
}
try {
inputDeviceCooperate.on('cooperation', callback);
} catch (error) {
console.log(`Register failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
off(‘cooperation’)
off(type: ‘cooperation’, callback?: AsyncCallback<void>): void
Disables listening for screen hopping status change events.
System capability: SystemCapability.MultimodalInput.Input.Cooperator
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type. The value is cooperation. |
callback | AsyncCallback<void> | No | Callback to be unregistered. If this parameter is not specified, all callbacks registered by the current application will be unregistered. |
Example
import inputDeviceCooperate from '@ohos.multimodalInput.inputDeviceCooperate'
// Unregister a single callback.
function callbackOn(deviceDescriptor: string, eventMsg: inputDeviceCooperate.EventMsg) {
console.log(`Keyboard mouse crossing event: ${JSON.stringify(deviceDescriptor)}`);
return false;
}
function callbackOff() {
console.log(`Keyboard mouse crossing event`);
return false;
}
try {
inputDeviceCooperate.on('cooperation', callbackOn);
inputDeviceCooperate.off("cooperation", callbackOff);
} catch (error) {
console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
import inputDeviceCooperate from '@ohos.multimodalInput.inputDeviceCooperate'
// Unregister all callbacks.
function callback(deviceDescriptor: string, eventMsg: inputDeviceCooperate.EventMsg) {
console.log(`Keyboard mouse crossing event: ${JSON.stringify(deviceDescriptor)}`);
return false;
}
try {
inputDeviceCooperate.on('cooperation', callback);
inputDeviceCooperate.off("cooperation");
} catch (error) {
console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
EventMsg
Enumerates screen hopping event.
System capability: SystemCapability.MultimodalInput.Input.Cooperator
Name | Value | Description |
---|---|---|
MSG_COOPERATE_INFO_START | 200 | Screen hopping starts. |
MSG_COOPERATE_INFO_SUCCESS | 201 | Screen hopping succeeds. |
MSG_COOPERATE_INFO_FAIL | 202 | Screen hopping fails. |
MSG_COOPERATE_STATE_ON | 500 | Screen hopping is enabled. |
MSG_COOPERATE_STATE_OFF | 501 | Screen hopping is disabled. |
你可能感兴趣的鸿蒙文章
harmony 鸿蒙System Common Events (To Be Deprecated Soon)
harmony 鸿蒙System Common Events
harmony 鸿蒙API Reference Document Description
harmony 鸿蒙Enterprise Device Management Overview (for System Applications Only)
harmony 鸿蒙BundleStatusCallback
harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager)
harmony 鸿蒙@ohos.distributedBundle (Distributed Bundle Management)
harmony 鸿蒙@ohos.bundle (Bundle)
harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦