提交 5dc0a29a 编写于 作者: S shawn_he

update doc

Signed-off-by: Nshawn_he <shawn.he@huawei.com>
上级 85593757
......@@ -215,6 +215,7 @@
- [@ohos.geolocation](js-apis-geolocation.md)
- [@ohos.multimodalInput.inputConsumer](js-apis-inputconsumer.md)
- [@ohos.multimodalInput.inputDevice](js-apis-inputdevice.md)
- [@ohos.multimodalInput.inputDeviceCooperate](js-apis-cooperate.md)
- [@ohos.multimodalInput.inputEvent](js-apis-inputevent.md)
- [@ohos.multimodalInput.inputEventClient](js-apis-inputeventclient.md)
- [@ohos.multimodalInput.inputMonitor](js-apis-inputmonitor.md)
......
# Screen Hopping
The Screen Hopping module enables two or more networked devices to share the keyboard and mouse for collaborative operations.
> **Description**
>
> 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.
## Modules to Import
```js
import inputDeviceCooperate from '@ohos.multimodalInput.inputDeviceCooperate'
```
## inputDeviceCooperate.enable
enable(enable: boolean, callback: AsyncCallback&lt;void&gt;): void
Specifies whether to enable screen hopping. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.InputDeviceCooperate
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | --------------------------- |
| enable | boolean | Yes | Whether to enable screen hopping.|
| callback | AsyncCallback&lt;void&gt; | Yes |Callback used to return the result. |
**Example**
```js
try {
inputDeviceCooperate.enable(true, (error) => {
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&lt;void&gt;
Specifies whether to enable screen hopping. This API uses a promise to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.InputDeviceCooperate
**Parameters**
| Name | Type | Mandatory | Description |
| --------- | ------- | ---- | ------------------------------------------------------------------- |
| enable | boolean | Yes | Whether to enable screen hopping. |
**Return value**
| Name | Description |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. |
**Example**
```js
try {
inputDeviceCooperate.enable(true).then(() => {
console.log(`Keyboard mouse crossing enable success.`);
}, (error) => {
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.InputDeviceCooperate
**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](../errorcodes/errorcodes-multimodalinput.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 4400001 | This error code is reported if an invalid device descriptor is passed to the screen hopping API. |
| 4400002 | This error code is reported if the screen hopping status is abnormal when the screen hopping API is called. |
**Example**
```js
try {
inputDeviceCooperate.start(sinkDeviceDescriptor, srcInputDeviceId, (error) => {
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.InputDeviceCooperate
**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](../errorcodes/errorcodes-multimodalinput.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 4400001 | This error code is reported if an invalid device descriptor is passed to the screen hopping API. |
| 4400002 | This error code is reported if the screen hopping status is abnormal when the screen hopping API is called. |
**Example**
```js
try {
inputDeviceCooperate.start(sinkDeviceDescriptor, srcInputDeviceId).then(() => {
console.log(`Start Keyboard mouse crossing success.`);
}, (error) => {
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.InputDeviceCooperate
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------- | ---- | ---------------------------- |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. |
**Example**
```js
try {
inputDeviceCooperate.stop((error) => {
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.InputDeviceCooperate
**Parameters**
| Name | Description |
| -------- | ---------------------------- |
| Promise\<void> | Promise used to return the result. |
**Example**
```js
try {
inputDeviceCooperate.stop().then(() => {
console.log(`Stop Keyboard mouse crossing success.`);
}, (error) => {
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.InputDeviceCooperate
**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**
```js
try {
inputDeviceCooperate.getState(deviceDescriptor, (error, data) => {
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.InputDeviceCooperate
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | --------- | ---- | ---------------------------- |
| deviceDescriptor | string | Yes | Descriptor of the target device for screen hopping. |
**Return value**
| Name | Description |
| ------------------- | ------------------------------- |
| Promise<{ state: boolean }>| Promise used to return the result. |
**Example**
```js
try {
inputDeviceCooperate.getState(deviceDescriptor).then((data) => {
console.log(`Get the status success, data: ${JSON.stringify(data)}`);
}, (error) => {
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 events.
**System capability**: SystemCapability.MultimodalInput.Input.InputDeviceCooperate
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------------- | ---- | ---------------------------- |
| type | string | Yes | Event type. The value is **cooperation**. |
| callback | AsyncCallback<{ deviceDescriptor: string, eventMsg: [EventMsg](#eventmsg) }> | Yes | Callback used to return the result. |
**Example**
```js
try {
inputDeviceCooperate.on('cooperation', (data) => {
console.log(`Keyboard mouse crossing event: ${JSON.stringify(data)}`);
});
} catch (err) {
console.log(`Register failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
## off('cooperation')
off(type: 'cooperation', callback?: AsyncCallback\<void>): void
Disables listening for screen hopping events.
**System capability**: SystemCapability.MultimodalInput.Input.InputDeviceCooperate
**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**
```js
// Unregister a single callback.
callback: function(event) {
console.log(`Keyboard mouse crossing event: ${JSON.stringify(event)}`);
return false;
},
try {
inputDeviceCooperate.on('cooperation', this.callback);
inputDeviceCooperate.off("cooperation", this.callback);
} catch (error) {
console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
```js
// Unregister all callbacks.
callback: function(event) {
console.log(`Keyboard mouse crossing event: ${JSON.stringify(event)}`);
return false;
},
try {
inputDeviceCooperate.on('cooperation', this.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.InputDeviceCooperate
| 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. |
......@@ -38,12 +38,16 @@ This is a system API.
**Example**
```
let keyOptions = {preKeys: [], finalKey: 3, isFinalKeyDown: true, finalKeyDownDuration: 0}
let callback = function(keyOptions) {
console.info("preKeys: " + keyOptions.preKeys, "finalKey: " + keyOptions.finalKey,
"isFinalKeyDown: " + keyOptions.isFinalKeyDown, "finalKeyDownDuration: " + keyOptions.finalKeyDownDuration)
let keyOptions = { preKeys: [], finalKey: 18, isFinalKeyDown: true, finalKeyDownDuration: 0 }
let callback = function (keyOptions) {
console.info("preKeys: " + keyOptions.preKeys, "finalKey: " + keyOptions.finalKey,
"isFinalKeyDown: " + keyOptions.isFinalKeyDown, "finalKeyDownDuration: " + keyOptions.finalKeyDownDuration)
}
try {
inputConsumer.on(inputConsumer.SubscribeType.KEY, keyOptions, callback);
} catch (error) {
console.info(`inputConsumer.on, error.code=${JSON.stringify(error.code)}, error.msg=${JSON.stringify(error.message)}`);
}
inputConsumer.on('key', keyOptions, callback);
```
......@@ -68,12 +72,16 @@ This is a system API.
**Example**
```
let keyOptions = {preKeys: [], finalKey: 18, isFinalKeyDown: true, finalKeyDownDuration: 0}
let callback = function(keyOptions) {
console.info("preKeys: " + keyOptions.preKeys, "finalKey: " + keyOptions.finalKey,
"isFinalKeyDown: " + keyOptions.isFinalKeyDown, "finalKeyDownDuration: " + keyOptions.finalKeyDownDuration)
let keyOptions = { preKeys: [], finalKey: 18, isFinalKeyDown: true, finalKeyDownDuration: 0 }
let callback = function (keyOptions) {
console.info("preKeys: " + keyOptions.preKeys, "finalKey: " + keyOptions.finalKey,
"isFinalKeyDown: " + keyOptions.isFinalKeyDown, "finalKeyDownDuration: " + keyOptions.finalKeyDownDuration)
}
try {
inputConsumer.off(inputConsumer.SubscribeType.KEY, keyOptions, callback);
} catch (error) {
console.info(`inputConsumer.off, error.code=${JSON.stringify(error.code)}, error.msg=${JSON.stringify(error.message)}`);
}
inputConsumer.off('key', keyOptions, callback);
```
......
......@@ -15,6 +15,130 @@ The Input Device module implements listening for connection, disconnection, and
```js
import inputDevice from '@ohos.multimodalInput.inputDevice';
```
## inputDevice.getDeviceList<sup>9+</sup>
getDeviceList(callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
Obtains the IDs of all input devices. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------------------------- | ---- | ---------- |
| callback | AsyncCallback&lt;Array&lt;number&gt;&gt; | Yes | Callback used to return the result.|
**Example**
```js
try {
inputDevice.getDeviceList((error, ids) => {
if (error) {
console.log(`Failed to get device list.
error code=${JSON.stringify(err.code)} msg=${JSON.stringify(err.message)}`);
return;
}
this.data = ids;
console.log("The device ID list is: " + ids);
});
} catch (error) {
console.info("getDeviceList " + error.code + " " + error.message);
}
```
## inputDevice.getDeviceList<sup>9+</sup>
getDeviceList(): Promise&lt;Array&lt;number&gt;&gt;
Obtains the IDs of all input devices. This API uses a promise to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Return value**
| Name | Description |
| ---------------------------------- | ------------------------------- |
| Promise&lt;Array&lt;number&gt;&gt; | Promise used to return the result.|
**Example**
```js
try {
inputDevice.getDeviceList().then((ids) => {
console.log("The device ID list is: " + ids);
});
} catch (error) {
console.info("getDeviceList " + error.code + " " + error.message);
}
```
## inputDevice.getDeviceInfo<sup>9+</sup>
getDeviceInfo(deviceId: number, callback: AsyncCallback&lt;InputDeviceData&gt;): void
Obtains information about an input device. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------------------------------------------- | ---- | --------------------------------------- |
| deviceId | number | Yes | ID of the input device. |
| callback | AsyncCallback&lt;[InputDeviceData](#inputdevicedata)&gt; | Yes | Callback used to return the result, which is an **InputDeviceData** object.|
**Example**
```js
// Obtain the name of the device whose ID is 1.
try {
inputDevice.getDeviceInfo(1, (error, inputDevice) => {
if (error) {
console.log(`Failed to get device information.
error code=${JSON.stringify(err.code)} msg=${JSON.stringify(err.message)}`);
return;
}
console.log("The device name is: " + inputDevice.name);
});
} catch (error) {
console.info("getDeviceInfo " + error.code + " " + error.message);
}
```
## inputDevice.getDeviceInfo<sup>9+</sup>
getDeviceInfo(deviceId: number): Promise&lt;InputDeviceData&gt;
Obtains information about an input device. This API uses a promise to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ---------------------- |
| deviceId | number | Yes | ID of the input device.|
**Return value**
| Name | Description |
| -------------------------------------------------- | ------------------------------- |
| Promise&lt;[InputDeviceData](#inputdevicedata)&gt; | Promise used to return the result.|
**Example**
```js
// Obtain the name of the device whose ID is 1.
try {
inputDevice.getDeviceInfo(id).then((inputDevice) => {
console.log("The device name is: " + inputDevice.name);
});
} catch (error) {
console.info("getDeviceInfo " + error.code + " " + error.message);
}
```
## inputDevice.on<sup>9+</sup>
......@@ -35,20 +159,24 @@ Enables listening for hot swap events of an input device.
```js
let isPhysicalKeyboardExist = true;
inputDevice.on("change", (data) => {
try {
inputDevice.on("change", (data) => {
console.log("type: " + data.type + ", deviceId: " + data.deviceId);
inputDevice.getKeyboardType(data.deviceId, (err, ret) => {
console.log("The keyboard type of the device is: " + ret);
if (ret == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'add') {
// The physical keyboard is connected.
isPhysicalKeyboardExist = true;
} else if (ret == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'remove') {
// The physical keyboard is disconnected.
isPhysicalKeyboardExist = false;
}
console.log("The keyboard type of the device is: " + ret);
if (ret == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'add') {
// The physical keyboard is connected.
isPhysicalKeyboardExist = true;
} else if (ret == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'remove') {
// The physical keyboard is disconnected.
isPhysicalKeyboardExist = false;
}
});
});
// Check whether the soft keyboard is open based on the value of isPhysicalKeyboardExist.
});
// Check whether the soft keyboard is open based on the value of isPhysicalKeyboardExist.
} catch (error) {
console.info("oninputdevcie " + error.code + " " + error.message);
}
```
## inputDevice.off<sup>9+</sup>
......@@ -69,24 +197,40 @@ Disables listening for hot swap events of an input device.
**Example**
```js
function listener(data) {
console.log("type: " + data.type + ", deviceId: " + data.deviceId);
callback: function(data) {
console.log("type: " + data.type + ", deviceId: " + data.deviceId);
}
try {
inputDevice.on("change", this.callback);
} catch (error) {
console.info("oninputdevcie " + error.code + " " + error.message)
}
// Disable this listener.
inputDevice.off("change", listener);
try {
inputDevice.off("change", this.callback);
} catch (error) {
console.info("offinputdevcie " + error.code + " " + error.message)
}
// Disable all listeners.
inputDevice.off("change");
try {
inputDevice.off("change");
} catch (error) {
console.info("offinputdevcie " + error.code + " " + error.message);
}
// By default, the soft keyboard is closed when listening is disabled.
```
## inputDevice.getDeviceIds
## inputDevice.getDeviceIds<sup>(deprecated)</sup>
getDeviceIds(callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
Obtains the IDs of all input devices. This API uses an asynchronous callback to return the result.
This API is deprecated since API version 9. You are advised to use [inputDevice.getDeviceList](#inputdevicegetdevicelist9) instead.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Parameters**
......@@ -103,12 +247,14 @@ inputDevice.getDeviceIds((ids)=>{
});
```
## inputDevice.getDeviceIds
## inputDevice.getDeviceIds<sup>(deprecated)</sup>
getDeviceIds(): Promise&lt;Array&lt;number&gt;&gt;
Obtains the IDs of all input devices. This API uses a promise to return the result.
This API is deprecated since API version 9. You are advised to use [inputDevice.getDeviceList](#inputdevicegetdevicelist9) instead.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Return value**
......@@ -125,12 +271,14 @@ inputDevice.getDeviceIds().then((ids)=>{
});
```
## inputDevice.getDevice
## inputDevice.getDevice<sup>(deprecated)</sup>
getDevice(deviceId: number, callback: AsyncCallback&lt;InputDeviceData&gt;): void
Obtains information about an input device. This API uses an asynchronous callback to return the result.
This API is deprecated since API version 9. You are advised to use [inputDevice.getDeviceInfo](#inputdevicegetdeviceinfo9) instead.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Parameters**
......@@ -149,12 +297,14 @@ inputDevice.getDevice(1, (inputDevice)=>{
});
```
## inputDevice.getDevice
## inputDevice.getDevice<sup>(deprecated)</sup>
getDevice(deviceId: number): Promise&lt;InputDeviceData&gt;
Obtains information about an input device. This API uses a promise to return the result.
This API is deprecated since API version 9. You are advised to use [inputDevice.getDeviceInfo](#inputdevicegetdeviceinfo9) instead.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Parameters**
......@@ -198,9 +348,13 @@ Obtains the key codes supported by the input device. This API uses an asynchrono
```js
// Check whether the input device whose ID is 1 supports key codes 17, 22, and 2055.
inputDevice.supportKeys(1, [17, 22, 2055], (ret)=>{
try {
inputDevice.supportKeys(1, [17, 22, 2055], (error, ret) => {
console.log("The query result is as follows: " + ret);
});
});
} catch (error) {
console.info("supportKeys " + error.code + " " + error.message);
}
```
## inputDevice.supportKeys<sup>9+</sup>
......@@ -228,9 +382,13 @@ Obtains the key codes supported by the input device. This API uses a promise to
```js
// Check whether the input device whose ID is 1 supports key codes 17, 22, and 2055.
inputDevice.supportKeys(1, [17, 22, 2055]).then((ret)=>{
try {
inputDevice.supportKeys(1, [17, 22, 2055]).then((ret) => {
console.log("The query result is as follows: " + ret);
})
});
} catch (error) {
console.info("supportKeys " + error.code + " " + error.message);
}
```
## inputDevice.getKeyboardType<sup>9+</sup>
......@@ -252,9 +410,18 @@ Obtains the keyboard type of an input device. This API uses an asynchronous call
```js
// Query the keyboard type of the input device whose ID is 1.
inputDevice.getKeyboardType(1, (ret)=>{
console.log("The keyboard type of the device is: " + ret);
});
try {
inputDevice.getKeyboardType(1, (error, number) => {
if (error) {
console.log(`Failed to get keyboardtype.
error code=${JSON.stringify(err.code)} msg=${JSON.stringify(err.message)}`);
return;
}
console.log("The keyboard type of the device is: " + number);
});
} catch (error) {
console.info("getKeyboardType " + error.code + " " + error.message);
}
```
## inputDevice.getKeyboardType<sup>9+</sup>
......@@ -275,9 +442,13 @@ Obtains the keyboard type of an input device. This API uses a promise to return
```js
// Query the keyboard type of the input device whose ID is 1.
inputDevice.getKeyboardType(1).then((ret)=>{
console.log("The keyboard type of the device is: " + ret);
})
try {
inputDevice.getKeyboardType(1).then((number) => {
console.log("The keyboard type of the device is: " + number);
});
} catch (error) {
console.info("getKeyboardType " + error.code + " " + error.message);
}
```
## DeviceListener<sup>9+</sup>
......
......@@ -36,13 +36,24 @@ This is a system API.
**Example**
```js
let keyEvent = {
try {
var keyEvent = {
isPressed: true,
keyCode: 2,
keyDownDuration: 0,
isIntercepted: false
}
inputEventClient.injectKeyEvent({ KeyEvent: keyEvent });
var keyEvent1 = {
isPressed: false,
keyCode: 2,
keyDownDuration: 0,
isIntercepted: false
};
inputEventClient.injectKeyEvent({ KeyEvent: keyEvent1 });
} catch (error) {
console.info("injectKeyEvent " + error.code + " " + error.message);
}
let res = inputEventClient.injectEvent({KeyEvent: keyEvent});
```
......
......@@ -43,10 +43,14 @@ This is a system API.
**Example**
```js
inputMonitor.off("touch", (event) => {
// A touch event is consumed.
return false;
});
try {
inputMonitor.on("touch", (data)=> {
console.info(`monitorOnTouchEvent success ${JSON.stringify(data)}`);
return false;
});
} catch (error) {
console.info("onMonitor " + error.code + " " + error.message)
}
```
on(type: "mouse", receiver: Callback&lt;MouseEvent&gt;): void
......@@ -69,13 +73,16 @@ This is a system API.
**Example**
```js
inputMonitor.off("mouse", (event) => {
// A mouse event is consumed.
});
try {
inputMonitor.on("mouse", (data)=> {
console.info(`monitorOnMouseEvent success ${JSON.stringify(data)}`);
return false;
});
} catch (error) {
console.info("onMonitor " + error.code + " " + error.message)
}
```
## inputMonitor.off
off(type: "touch", receiver?: TouchEventReceiver): void
......@@ -98,7 +105,26 @@ This is a system API.
**Example**
```js
inputMonitor.off("touch");
// 取消所有监听。
try {
inputMonitor.off("touch");
} catch (error) {
console.info("offMonitor " + error.code + " " + error.message)
}
// 单独取消receiver的监听。
callback:function(data) {
console.info(`call success ${JSON.stringify(data)}`);
},
try {
inputMonitor.on("touch", this.callback);
} catch (error) {
console.info("onTouchMonitor " + error.code + " " + error.message)
}
try {
inputMonitor.off("touch",this.callback);
} catch (error) {
console.info("offTouchMonitor " + error.code + " " + error.message)
}
```
off(type: "mouse", receiver?:Callback\<MouseEvent>):void
......@@ -121,7 +147,26 @@ This is a system API.
**Example**
```js
inputMonitor.off("mouse");
// 取消所有监听。
try {
inputMonitor.off("mouse");
} catch (error) {
console.info("offMonitor " + error.code + " " + error.message)
}
// 单独取消receiver的监听。
callback:function(data) {
console.info(`call success ${JSON.stringify(data)}`);
},
try {
inputMonitor.on("mouse", this.callback);
} catch (error) {
console.info("onMouseMonitor " + error.code + " " + error.message)
}
try {
inputMonitor.off("mouse", this.callback);
} catch (error) {
console.info("offMouseMonitor " + error.code + " " + error.message)
}
```
......@@ -149,9 +194,13 @@ This is a system API.
**Example**
```js
inputMonitor.on("touch", (event) => {
// A touch event is consumed.
return false;
});
inputMonitor.off("touch");
try {
inputMonitor.on("touch", (event) => {
// 若返回true,表示本次操作后续所有事件不再分发到窗口,事件都由监听者消费。
return false;
});
inputMonitor.off("touch");
} catch (error) {
console.info("offMonitor " + error.code + " " + error.message)
}
```
......@@ -12,7 +12,7 @@ The mouse pointer module provides APIs related to pointer attribute management.
import pointer from '@ohos.multimodalInput.pointer';
```
## pointer.setPointerVisibele
## pointer.setPointerVisible<sup>9+</sup>
setPointerVisible(visible: boolean, callback: AsyncCallback&lt;void&gt;): void
......@@ -22,24 +22,28 @@ Sets the visible status of the mouse pointer. This API uses an asynchronous call
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------------------------------------------- |
| visible | boolean | Yes | Whether the mouse pointer is visible. The value **true** indicates that the mouse pointer is visible, and the value **false** indicates the opposite.|
| callback | AysncCallback&lt;void&gt; | Yes | Callback used to return the result. |
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ---------------------------------------- |
| visible | boolean | Yes | Whether the mouse pointer is visible.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result.|
**Example**
```js
pointer.setPointerVisible(true, (err, data) => {
if (err) {
console.log(`set pointer visible failed. err=${JSON.stringify(err)}`);
return;
try {
pointer.setPointerVisible(true, (error) => {
if (error) {
console.log(`Set pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
return;
}
console.log(`set pointer visible success.`);
);
console.log(`Set pointer visible success`);
});
} catch (error) {
console.log(`Set pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
## pointer.setPointerVisible
## pointer.setPointerVisible<sup>9+</sup>
setPointerVisible(visible: boolean): Promise&lt;void&gt;
......@@ -49,66 +53,400 @@ Sets the visible status of the mouse pointer. This API uses a promise to return
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------- | ---- | ------------------------------------------------------------------- |
| visible | boolean | Yes | Whether the mouse pointer is visible. The value **true** indicates that the mouse pointer is visible, and the value **false** indicates the opposite.|
| Name | Type | Mandatory | Description |
| ------- | ------- | ---- | ---------------------------------------- |
| visible | boolean | Yes | Whether the mouse pointer is visible.|
**Return value**
| Parameter | Description |
| ------------------- | ------------------------------- |
| Name | Description |
| ------------------- | ------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
**Example**
```js
pointer.setPointerVisible(false).then( data => {
console.log(`set mouse pointer visible success`);
}, data => {
console.log(`set mouse pointer visible failed err=${JSON.stringify(data)}`);
});
try {
pointer.setPointerVisible(false).then(() => {
console.log(`Set pointer visible success`);
});
} catch (error) {
console.log(`Set pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
## pointer.isPointerVisible
## pointer.isPointerVisible<sup>9+</sup>
isPointerVisible(callback: AsyncCallback&lt;boolean&gt;): void
Checks the visible status of the mouse pointer. This API uses an asynchronous callback to return the result.
Checks the visible status of the mouse pointer. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.Pointer
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------------- | ---- | ---------------------------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the result.|
| Name | Type | Mandatory | Description |
| -------- | ---------------------------- | ---- | -------------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the result.|
**Example**
```js
pointer.isPointerVisible((visible)=>{
console.log("The mouse pointer visible attributes is " + visible);
});
try {
pointer.isPointerVisible((error, visible) => {
if (error) {
console.log(`Get pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
return;
}
console.log(`Get pointer visible success, visible: ${JSON.stringify(visible)}`);
});
} catch (error) {
console.log(`Get pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
## pointer.isPointerVisible
## pointer.isPointerVisible<sup>9+</sup>
isPointerVisible(): Promise&lt;boolean&gt;
Checks the visible status of the mouse pointer. This API uses a promise to return the result.
Checks the visible status of the mouse pointer. This API uses a promise to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.Pointer
**Return value**
| Parameter | Description |
| ---------------------- | ------------------------------- |
| Name | Description |
| ---------------------- | ------------------- |
| Promise&lt;boolean&gt; | Promise used to return the result.|
**Example**
```js
pointer.isPointerVisible().then( data => {
console.log(`isPointerThen success data=${JSON.stringify(data)}`);
pointer.isPointerVisible().then((visible) => {
console.log(`Get pointer visible success, visible: ${JSON.stringify(visible)}`);
});
```
## pointer.setPointerSpeed<sup>9+</sup>
setPointerSpeed(speed: number, callback: AsyncCallback&lt;void&gt;): void
Sets the mouse movement speed. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.Pointer
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ------------------------------------- |
| speed | number | Yes | Mouse movement speed. The value ranges from **1** to **11**. The default value is **5**. |
| callback | AysncCallback&lt;void&gt; | Yes | Callback used to return the result.|
**Example**
```js
try {
pointer.setPointerSpeed(5, (error) => {
if (error) {
console.log(`Set pointer speed failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
return;
}
console.log(`Set pointer speed success`);
});
} catch (error) {
console.log(`Set pointer speed failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
## pointer.setPointerSpeed<sup>9+</sup>
setPointerSpeed(speed: number): Promise&lt;void&gt;
Sets the mouse movement speed. This API uses a promise to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.Pointer
**Parameters**
| Name | Type | Mandatory | Description |
| ----- | ------ | ---- | ----------------------------------- |
| speed | number | Yes | Mouse movement speed. The value ranges from **1** to **11**. The default value is **5**.|
**Return value**
| Name | Description |
| ------------------- | ---------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
**Example**
```js
try {
pointer.setPointerSpeed(5).then(() => {
console.log(`Set pointer speed success`);
});
} catch (error) {
console.log(`Set pointer speed failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
## pointer.getPointerSpeed<sup>9+</sup>
getPointerSpeed(callback: AsyncCallback&lt;number&gt;): void
Obtains the mouse movement speed. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.Pointer
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | --------------------------- | ---- | -------------- |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the result.|
**Example**
```js
try {
pointer.getPointerSpeed((error, speed) => {
if (error) {
console.log(`Get pointer speed failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
return;
}
console.log(`Get pointer speed success, speed: ${JSON.stringify(speed)}`);
});
} catch (error) {
console.log(`Get pointer speed failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
## pointer.getPointerSpeed<sup>9+</sup>
getPointerSpeed(): Promise&lt;number&gt;
Obtains the mouse movement speed. This API uses a promise to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.Pointer
**Return value**
| Name | Description |
| --------------------- | ------------------- |
| Promise&lt;number&gt; | Promise used to return the result.|
**Example**
```js
try {
pointer.getPointerSpeed().then(speed => {
console.log(`Get pointer speed success, speed: ${JSON.stringify(speed)}`);
});
} catch (error) {
console.log(`Get pointer speed failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
## pointer.getPointerStyle<sup>9+</sup>
getPointerStyle(windowId: number, callback: AsyncCallback&lt;PointerStyle&gt;): void
Obtains the mouse pointer style. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.Pointer
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | -------------- |
| windowId | number | Yes | Window ID. |
| callback | AsyncCallback&lt;[PointerStyle](#pointerstyle9)&gt; | Yes | Callback used to return the result.|
**Example**
```js
import window from '@ohos.window';
window.getTopWindow((error, win) => {
win.getProperties((error, properties) => {
var windowId = properties.id;
if (windowId < 0) {
console.log(`Invalid windowId`);
return;
}
try {
pointer.getPointerStyle(windowId, (error, style) => {
console.log(`Get pointer style success, style: ${JSON.stringify(style)}`);
});
} catch (error) {
console.log(`Get pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
});
});
```
## pointer.getPointerStyle<sup>9+</sup>
getPointerStyle(windowId: number): Promise&lt;PointerStyle&gt;
Obtains the mouse pointer style. This API uses a promise to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.Pointer
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------ | ---- | -------- |
| windowId | number | Yes | Window ID.|
**Return value**
| Name | Description |
| ---------------------------------------- | ------------------- |
| Promise&lt;[PointerStyle](#pointerstyle9)&gt; | Promise used to return the result.|
**Example**
```js
import window from '@ohos.window';
window.getTopWindow((error, win) => {
win.getProperties((error, properties) => {
var windowId = properties.id;
if (windowId < 0) {
console.log(`Invalid windowId`);
return;
}
try {
pointer.getPointerStyle(windowId).then((style) => {
console.log(`Get pointer style success, style: ${JSON.stringify(style)}`);
});
} catch (error) {
console.log(`Get pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
});
});
```
## pointer.setPointerStyle<sup>9+</sup>
setPointerStyle(windowId: number, pointerStyle: PointerStyle, callback: AsyncCallback&lt;void&gt;): void
Sets the mouse pointer style. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.Pointer
**Parameters**
| Name | Type | Mandatory | Description |
| ------------ | ------------------------------ | ---- | ----------------------------------- |
| windowId | number | Yes | Window ID. |
| pointerStyle | [PointerStyle](#pointerstyle9) | Yes | Mouse pointer style ID. |
| callback | AysncCallback&lt;void&gt; | Yes | Callback used to return the result.|
**Example**
```js
import window from '@ohos.window';
window.getTopWindow((error, win) => {
win.getProperties((error, properties) => {
var windowId = properties.id;
if (windowId < 0) {
console.log(`Invalid windowId`);
return;
}
try {
pointer.setPointerStyle(windowId, pointer.PointerStyle.CROSS, error => {
console.log(`Set pointer style success`);
});
} catch (error) {
console.log(`Set pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
});
});
```
## pointer.setPointerStyle<sup>9+</sup>
setPointerStyle(windowId: number, pointerStyle: PointerStyle): Promise&lt;void&gt;
Sets the mouse pointer style. This API uses a promise to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.Pointer
**Parameters**
| Name | Type | Mandatory | Description |
| ------------------- | ------------------------------ | ---- | ---------------- |
| windowId | number | Yes | Window ID. |
| pointerStyle | [PointerStyle](#pointerstyle9) | Yes | Mouse pointer style ID. |
| Promise&lt;void&gt; | void | Yes | Promise used to return the result.|
**Example**
```js
import window from '@ohos.window';
window.getTopWindow((error, win) => {
win.getProperties((error, properties) => {
var windowId = properties.id;
if (windowId < 0) {
console.log(`Invalid windowId`);
return;
}
try {
pointer.setPointerStyle(windowId, pointer.PointerStyle.CROSS).then(() => {
console.log(`Set pointer style success`);
});
} catch (error) {
console.log(`Set pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
});
});
```
## PointerStyle<sup>9+</sup>
Enumerates mouse pointer styles.
**System capability**: SystemCapability.MultimodalInput.Input.Pointer
| Name | Value | Description |
| -------------------------------- | ---- | ------ |
| DEFAULT | 0 | Default |
| EAST | 1 | East arrow |
| WEST | 2 | West arrow |
| SOUTH | 3 | South arrow |
| NORTH | 4 | North arrow |
| WEST_EAST | 5 | West-east arrow |
| NORTH_SOUTH | 6 | North-south arrow |
| NORTH_EAST | 7 | North-east arrow |
| NORTH_WEST | 8 | North-west arrow |
| SOUTH_EAST | 9 | South-east arrow |
| SOUTH_WEST | 10 | South-west arrow |
| NORTH_EAST_SOUTH_WEST | 11 | North-east and south-west adjustment|
| NORTH_WEST_SOUTH_EAST | 12 | North-west and south-east adjustment|
| CROSS | 13 | Cross (accurate selection) |
| CURSOR_COPY | 14 | Copy cursor |
| CURSOR_FORBID | 15 | Forbid cursor |
| COLOR_SUCKER | 16 | Sucker |
| HAND_GRABBING | 17 | Grabbing hand |
| HAND_OPEN | 18 | Opening hand |
| HAND_POINTING | 19 | Hand-shaped pointer |
| HELP | 20 | Help |
| MOVE | 21 | Move |
| RESIZE_LEFT_RIGHT | 22 | Left and right resizing|
| RESIZE_UP_DOWN | 23 | Up and down resizing|
| SCREENSHOT_CHOOSE | 24 | Screenshot crosshair|
| SCREENSHOT_CURSOR | 25 | Screenshot cursor |
| TEXT_CURSOR | 26 | Text cursor |
| ZOOM_IN | 27 | Zoom in |
| ZOOM_OUT | 28 | Zoom out |
| MIDDLE_BTN_EAST | 29 | Scrolling east |
| MIDDLE_BTN_WEST | 30 | Scrolling west |
| MIDDLE_BTN_SOUTH | 31 | Scrolling south |
| MIDDLE_BTN_NORTH | 32 | Scrolling north |
| MIDDLE_BTN_NORTH_SOUTH | 33 | Scrolling north-south |
| MIDDLE_BTN_NORTH_EAST | 34 | Scrolling north-east |
| MIDDLE_BTN_NORTH_WEST | 35 | Scrolling north-west |
| MIDDLE_BTN_SOUTH_EAST | 36 | Scrolling south-east |
| MIDDLE_BTN_SOUTH_WEST | 37 | Scrolling south-west |
| MIDDLE_BTN_NORTH_SOUTH_WEST_EAST | 38 | Moving as a cone in four directions|
# Screen Hopping Error Codes
## 4400001 Incorrect Target Device Descriptor
**Error Message**
Incorrect descriptor for the target device.
**Description**
This error code is reported if an invalid device descriptor is passed to the screen hopping API.
**Possible Causes**
1. The target device does not exist, or the device is not networked.
2. The target device descriptor is empty.
**Solution**
1. Check whether the target device for screen hopping is correctly networked with the local device.
2. Set the target device descriptor correctly.
## 4400002 Input Device Operation Failed
**Error Message**
Failed to operate the input device.
**Description**
This error code is reported if the screen hopping status is abnormal when the screen hopping API is called.
**Possible Causes**
1. When screen hopping is initiated, the local device is in the hopped state.
2. When screen hopping is disabled, the local device is in the free state.
3. When screen hopping is disabled, the local device is in the hopping state.
**Solution**
1. When initiating screen hopping, make sure that the local device is not in the hopped state.
2. When disabling screen hopping, make sure that the local device is not in the free state.
3. When disabling screen hopping, make sure that the local device is not in the hopping state.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册