未验证 提交 eb74bef9 编写于 作者: O openharmony_ci 提交者: Gitee

!11152 inputdevice资料修改

Merge pull request !11152 from mayunteng/master
# 输入设备 # 输入设备
输入设备管理模块,用于监听输入设备连接、断开和变化,并查看输入设备相关信息。比如监听鼠标插拔,并获取鼠标的id、name和指针移动速度等信息。 输入设备管理模块,用于监听输入设备连接和断开状态,查询输入设备相关信息。
> **说明**: > **说明**:
...@@ -20,15 +20,15 @@ import inputDevice from '@ohos.multimodalInput.inputDevice'; ...@@ -20,15 +20,15 @@ import inputDevice from '@ohos.multimodalInput.inputDevice';
getDeviceList(callback: AsyncCallback<Array<number>>): void getDeviceList(callback: AsyncCallback<Array<number>>): void
获取所有输入设备的id列表,使用callback方式作为异步方法 获取所有输入设备的id列表,使用AsyncCallback异步方式返回结果
**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice **系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
**参数** **参数**
| 参数 | 类型 | 必填 | 说明 | | 参数 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | ---------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| callback | AsyncCallback<Array<number>> | 是 | 回调函数。 | | callback | AsyncCallback<Array<number>> | 是 | 回调函数,异步返回所有输入设备的id列表。 |
**示例** **示例**
...@@ -36,15 +36,13 @@ getDeviceList(callback: AsyncCallback<Array<number>>): void ...@@ -36,15 +36,13 @@ getDeviceList(callback: AsyncCallback<Array<number>>): void
try { try {
inputDevice.getDeviceList((error, ids) => { inputDevice.getDeviceList((error, ids) => {
if (error) { if (error) {
console.log(`Failed to get device list. console.log(`Failed to get device id list, error: ${JSON.stringify(error, [`code`, `message`])}`);
error code=${JSON.stringify(err.code)} msg=${JSON.stringify(err.message)}`);
return; return;
} }
this.data = ids; console.log(`Device id list: ${JSON.stringify(ids)}`);
console.log("The device ID list is: " + ids);
}); });
} catch (error) { } catch (error) {
console.info("getDeviceList " + error.code + " " + error.message); console.log(`Failed to get device id list, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
...@@ -52,25 +50,25 @@ try { ...@@ -52,25 +50,25 @@ try {
getDeviceList(): Promise<Array<number>> getDeviceList(): Promise<Array<number>>
获取所有输入设备的id列表,使用Promise方式作为异步方法 获取所有输入设备的id列表,使用Promise异步方式返回结果
**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice **系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
**返回值** **返回值**
| 参数 | 说明 | | 参数 | 说明 |
| ---------------------------------- | ------------------------------- | | ---------------------------------- | ------------------------------------------- |
| Promise<Array<number>> | Promise实例,用于异步获取结果。 | | Promise<Array<number>> | Promise对象,异步返回所有输入设备的id列表。 |
**示例** **示例**
```js ```js
try { try {
inputDevice.getDeviceList().then((ids) => { inputDevice.getDeviceList().then((ids) => {
console.log("The device ID list is: " + ids); console.log(`Device id list: ${JSON.stringify(ids)}`);
}); });
} catch (error) { } catch (error) {
console.info("getDeviceList " + error.code + " " + error.message); console.log(`Failed to get device id list, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
...@@ -78,7 +76,7 @@ try { ...@@ -78,7 +76,7 @@ try {
getDeviceInfo(deviceId: number, callback: AsyncCallback<InputDeviceData>): void getDeviceInfo(deviceId: number, callback: AsyncCallback<InputDeviceData>): void
获取输入设备的描述信息,使用callback方式作为异步方法 获取指定输入设备的信息,使用AsyncCallback异步方式返回结果
**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice **系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
...@@ -86,24 +84,23 @@ getDeviceInfo(deviceId: number, callback: AsyncCallback<InputDeviceData>): ...@@ -86,24 +84,23 @@ getDeviceInfo(deviceId: number, callback: AsyncCallback<InputDeviceData>):
| 参数 | 类型 | 必填 | 说明 | | 参数 | 类型 | 必填 | 说明 |
| -------- | -------------------------------------------------------- | ---- | --------------------------------------- | | -------- | -------------------------------------------------------- | ---- | --------------------------------------- |
| deviceId | number | 是 | 需要获取信息的设备id。 | | deviceId | number | 是 | 输入设备id。 |
| callback | AsyncCallback<[InputDeviceData](#inputdevicedata)> | 是 | 回调函数,异步返回InputDeviceData对象。 | | callback | AsyncCallback<[InputDeviceData](#inputdevicedata)> | 是 | 回调函数,异步返回输入设备信息。 |
**示例** **示例**
```js ```js
// 示例获取设备id为1的设备name信息。 // 获取输入设备id为1的设备信息。
try { try {
inputDevice.getDeviceInfo(1, (error, inputDevice) => { inputDevice.getDeviceInfo(1, (error, deviceData) => {
if (error) { if (error) {
console.log(`Failed to get device information. console.log(`Failed to get device info, error: ${JSON.stringify(error, [`code`, `message`])}`);
error code=${JSON.stringify(err.code)} msg=${JSON.stringify(err.message)}`);
return; return;
} }
console.log("The device name is: " + inputDevice.name); console.log(`Device info: ${JSON.stringify(deviceData)}`);
}); });
} catch (error) { } catch (error) {
console.info("getDeviceInfo " + error.code + " " + error.message); console.log(`Failed to get device info, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
...@@ -111,7 +108,7 @@ try { ...@@ -111,7 +108,7 @@ try {
getDeviceInfo(deviceId: number): Promise<InputDeviceData> getDeviceInfo(deviceId: number): Promise<InputDeviceData>
获取输入设备的描述信息,使用Promise方式作为异步方法 获取指定输入设备的信息,使用Promise异步方式返回结果
**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice **系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
...@@ -119,30 +116,30 @@ getDeviceInfo(deviceId: number): Promise<InputDeviceData> ...@@ -119,30 +116,30 @@ getDeviceInfo(deviceId: number): Promise<InputDeviceData>
| 参数 | 类型 | 必填 | 说明 | | 参数 | 类型 | 必填 | 说明 |
| -------- | ------ | ---- | ---------------------- | | -------- | ------ | ---- | ---------------------- |
| deviceId | number | 是 | 需要获取信息的设备id。 | | deviceId | number | 是 | 输入设备id。 |
**返回值** **返回值**
| 参数 | 说明 | | 参数 | 说明 |
| -------------------------------------------------- | ------------------------------- | | -------------------------------------------------- | ------------------------------- |
| Promise<[InputDeviceData](#inputdevicedata)> | Promise实例,用于异步获取结果。 | | Promise<[InputDeviceData](#inputdevicedata)> | Promise对象,异步返回输入设备信息。 |
**示例** **示例**
```js ```js
// 示例获取设备id为1的设备name信息。 // 获取输入设备id为1的设备信息。
try { try {
inputDevice.getDeviceInfo(id).then((inputDevice) => { inputDevice.getDeviceInfo(1).then((deviceData) => {
console.log("The device name is: " + inputDevice.name); console.log(`Device info: ${JSON.stringify(deviceData)}`);
}); });
} catch (error) { } catch (error) {
console.info("getDeviceInfo " + error.code + " " + error.message); console.log(`Failed to get device info, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
## inputDevice.on<sup>9+</sup> ## inputDevice.on<sup>9+</sup>
on(type: “change”, listener: Callback&lt;DeviceListener&gt;): void on(type: "change", listener: Callback&lt;DeviceListener&gt;): void
监听输入设备的热插拔事件。 监听输入设备的热插拔事件。
...@@ -153,7 +150,7 @@ on(type: “change”, listener: Callback&lt;DeviceListener&gt;): void ...@@ -153,7 +150,7 @@ on(type: “change”, listener: Callback&lt;DeviceListener&gt;): void
| 参数 | 类型 | 必填 | 说明 | | 参数 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | ----------- | | -------- | ---------------------------------------- | ---- | ----------- |
| type | string | 是 | 输入设备的事件类型。 | | type | string | 是 | 输入设备的事件类型。 |
| listener | Callback&lt;[DeviceListener](#devicelistener9)&gt; | 是 | 可上报的输入设备事件。 | | listener | Callback&lt;[DeviceListener](#devicelistener9)&gt; | 是 | 回调函数,异步上报输入设备热插拔事件。 |
**示例** **示例**
...@@ -161,13 +158,13 @@ on(type: “change”, listener: Callback&lt;DeviceListener&gt;): void ...@@ -161,13 +158,13 @@ on(type: “change”, listener: Callback&lt;DeviceListener&gt;): void
let isPhysicalKeyboardExist = true; let isPhysicalKeyboardExist = true;
try { try {
inputDevice.on("change", (data) => { inputDevice.on("change", (data) => {
console.log("type: " + data.type + ", deviceId: " + data.deviceId); console.log(`Device event info: ${JSON.stringify(data)}`);
inputDevice.getKeyboardType(data.deviceId, (err, ret) => { inputDevice.getKeyboardType(data.deviceId, (err, type) => {
console.log("The keyboard type of the device is: " + ret); console.log("The keyboard type is: " + type);
if (ret == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'add') { if (type == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'add') {
// 监听物理键盘已连接。 // 监听物理键盘已连接。
isPhysicalKeyboardExist = true; isPhysicalKeyboardExist = true;
} else if (ret == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'remove') { } else if (type == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'remove') {
// 监听物理键盘已断开。 // 监听物理键盘已断开。
isPhysicalKeyboardExist = false; isPhysicalKeyboardExist = false;
} }
...@@ -175,13 +172,13 @@ try { ...@@ -175,13 +172,13 @@ try {
}); });
// 根据isPhysicalKeyboardExist的值决定软键盘是否弹出。 // 根据isPhysicalKeyboardExist的值决定软键盘是否弹出。
} catch (error) { } catch (error) {
console.info("oninputdevcie " + error.code + " " + error.message); console.log(`Get device info failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
## inputDevice.off<sup>9+</sup> ## inputDevice.off<sup>9+</sup>
off(type: “change”, listener?: Callback&lt;DeviceListener&gt;): void off(type: "change", listener?: Callback&lt;DeviceListener&gt;): void
取消监听输入设备的热插拔事件。 取消监听输入设备的热插拔事件。
...@@ -192,42 +189,41 @@ off(type: “change”, listener?: Callback&lt;DeviceListener&gt;): void ...@@ -192,42 +189,41 @@ off(type: “change”, listener?: Callback&lt;DeviceListener&gt;): void
| 参数 | 类型 | 必填 | 说明 | | 参数 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | ----------- | | -------- | ---------------------------------------- | ---- | ----------- |
| type | string | 是 | 输入设备的事件类型。 | | type | string | 是 | 输入设备的事件类型。 |
| listener | Callback&lt;[DeviceListener](#devicelistener9)&gt; | 否 | 可上报的输入设备事件。 | | listener | Callback&lt;[DeviceListener](#devicelistener9)&gt; | 否 | 取消监听的回调函数。 |
**示例** **示例**
```js ```js
callback: function(data) { callback: function(data) {
console.log("type: " + data.type + ", deviceId: " + data.deviceId); console.log(`Report device event info: ${JSON.stringify(data, [`type`, `deviceId`])}`);
} }
try { try {
inputDevice.on("change", this.callback); inputDevice.on("change", this.callback);
} catch (error) { } catch (error) {
console.info("oninputdevcie " + error.code + " " + error.message) console.log(`Listen device event failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
// 单独取消listener的监听。 // 取消指定的监听。
try { try {
inputDevice.off("change", this.callback); inputDevice.off("change", this.callback);
} catch (error) { } catch (error) {
console.info("offinputdevcie " + error.code + " " + error.message) console.log(`Cancel listening device event failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
// 取消所有监听。 // 取消所有监听。
try { try {
inputDevice.off("change"); inputDevice.off("change");
} catch (error) { } catch (error) {
console.info("offinputdevcie " + error.code + " " + error.message); console.log(`Cancel all listening device event failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
// 取消监听后,软键盘默认都弹出。
``` ```
## inputDevice.getDeviceIds<sup>(deprecated)</sup> ## inputDevice.getDeviceIds<sup>(deprecated)</sup>
getDeviceIds(callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void getDeviceIds(callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
获取所有输入设备的id列表,使用callback方式作为异步方法 获取所有输入设备的id列表,使用AsyncCallback异步方式返回结果
从API version 9 开始不再维护,建议使用[inputDevice.getDeviceList](#inputdevicegetdevicelist9)代替。 从API version 9 开始不再维护,建议使用[inputDevice.getDeviceList](#inputdevicegetdevicelist9)代替。
...@@ -235,15 +231,19 @@ getDeviceIds(callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void ...@@ -235,15 +231,19 @@ getDeviceIds(callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
**参数** **参数**
| 参数 | 类型 | 必填 | 说明 | | 参数 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | ----- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| callback | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是 | 回调函数。 | | callback | AsyncCallback&lt;Array&lt;number&gt;&gt; | 是 | 回调函数,异步返回所有输入设备的id列表。 |
**示例** **示例**
```js ```js
inputDevice.getDeviceIds((ids)=>{ inputDevice.getDeviceList((error, ids) => {
console.log("The device ID list is: " + ids); if (error) {
console.log(`Failed to get device id list, error: ${JSON.stringify(error, [`code`, `message`])}`);
return;
}
console.log(`Device id list: ${JSON.stringify(ids)}`);
}); });
``` ```
...@@ -251,7 +251,7 @@ inputDevice.getDeviceIds((ids)=>{ ...@@ -251,7 +251,7 @@ inputDevice.getDeviceIds((ids)=>{
getDeviceIds(): Promise&lt;Array&lt;number&gt;&gt; getDeviceIds(): Promise&lt;Array&lt;number&gt;&gt;
获取所有输入设备的id列表,使用Promise方式作为异步方法 获取所有输入设备的id列表,使用Promise异步方式返回结果
从API version 9 开始不再维护,建议使用[inputDevice.getDeviceList](#inputdevicegetdevicelist9)代替。 从API version 9 开始不再维护,建议使用[inputDevice.getDeviceList](#inputdevicegetdevicelist9)代替。
...@@ -259,15 +259,15 @@ getDeviceIds(): Promise&lt;Array&lt;number&gt;&gt; ...@@ -259,15 +259,15 @@ getDeviceIds(): Promise&lt;Array&lt;number&gt;&gt;
**返回值** **返回值**
| 参数 | 说明 | | 参数 | 说明 |
| ---------------------------------- | ------------------- | | ---------------------------------- | ------------------------------------------- |
| Promise&lt;Array&lt;number&gt;&gt; | Promise实例,用于异步获取结果。 | | Promise&lt;Array&lt;number&gt;&gt; | Promise对象,异步返回所有输入设备的id列表。 |
**示例** **示例**
```js ```js
inputDevice.getDeviceIds().then((ids)=>{ inputDevice.getDeviceList().then((ids) => {
console.log("The device ID list is: " + ids); console.log(`Device id list: ${JSON.stringify(ids)}`);
}); });
``` ```
...@@ -275,7 +275,7 @@ inputDevice.getDeviceIds().then((ids)=>{ ...@@ -275,7 +275,7 @@ inputDevice.getDeviceIds().then((ids)=>{
getDevice(deviceId: number, callback: AsyncCallback&lt;InputDeviceData&gt;): void getDevice(deviceId: number, callback: AsyncCallback&lt;InputDeviceData&gt;): void
获取输入设备的描述信息,使用callback方式作为异步方法 获取指定输入设备的信息,使用AsyncCallback异步方式返回结果
从API version 9 开始不再维护,建议使用[inputDevice.getDeviceInfo](#inputdevicegetdeviceinfo9)代替。 从API version 9 开始不再维护,建议使用[inputDevice.getDeviceInfo](#inputdevicegetdeviceinfo9)代替。
...@@ -283,17 +283,21 @@ getDevice(deviceId: number, callback: AsyncCallback&lt;InputDeviceData&gt;): voi ...@@ -283,17 +283,21 @@ getDevice(deviceId: number, callback: AsyncCallback&lt;InputDeviceData&gt;): voi
**参数** **参数**
| 参数 | 类型 | 必填 | 说明 | | 参数 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | --------------------------- | | -------- | -------------------------------------------------------- | ---- | -------------------------------- |
| deviceId | number | 是 | 需要获取信息的设备id。 | | deviceId | number | 是 | 输入设备id。 |
| callback | AsyncCallback&lt;[InputDeviceData](#inputdevicedata)&gt; | 是 | 回调函数,异步返回InputDeviceData对象。 | | callback | AsyncCallback&lt;[InputDeviceData](#inputdevicedata)&gt; | 是 | 回调函数,异步返回输入设备信息。 |
**示例** **示例**
```js ```js
// 示例获取设备id为1的设备name信息。 // 获取输入设备id为1的设备信息。
inputDevice.getDevice(1, (inputDevice)=>{ inputDevice.getDeviceInfo(1, (error, deviceData) => {
console.log("The device name is: " + inputDevice.name); if (error) {
console.log(`Failed to get device info, error: ${JSON.stringify(error, [`code`, `message`])}`);
return;
}
console.log(`Device info: ${JSON.stringify(deviceData)}`);
}); });
``` ```
...@@ -301,7 +305,7 @@ inputDevice.getDevice(1, (inputDevice)=>{ ...@@ -301,7 +305,7 @@ inputDevice.getDevice(1, (inputDevice)=>{
getDevice(deviceId: number): Promise&lt;InputDeviceData&gt; getDevice(deviceId: number): Promise&lt;InputDeviceData&gt;
获取输入设备的描述信息,使用Promise方式作为异步方法 获取指定输入设备的信息,使用Promise异步方式返回结果
从API version 9 开始不再维护,建议使用[inputDevice.getDeviceInfo](#inputdevicegetdeviceinfo9)代替。 从API version 9 开始不再维护,建议使用[inputDevice.getDeviceInfo](#inputdevicegetdeviceinfo9)代替。
...@@ -309,22 +313,22 @@ getDevice(deviceId: number): Promise&lt;InputDeviceData&gt; ...@@ -309,22 +313,22 @@ getDevice(deviceId: number): Promise&lt;InputDeviceData&gt;
**参数** **参数**
| 参数 | 类型 | 必填 | 说明 | | 参数 | 类型 | 必填 | 说明 |
| -------- | ------ | ---- | ------------ | | -------- | ------ | ---- | ------------ |
| deviceId | number | 是 | 需要获取信息的设备id。 | | deviceId | number | 是 | 输入设备id。 |
**返回值** **返回值**
| 参数 | 说明 | | 参数 | 说明 |
| ---------------------------------------- | ------------------- | | -------------------------------------------------- | ----------------------------------- |
| Promise&lt;[InputDeviceData](#inputdevicedata)&gt; | Promise实例,用于异步获取结果。 | | Promise&lt;[InputDeviceData](#inputdevicedata)&gt; | Promise对象,异步返回输入设备信息。 |
**示例** **示例**
```js ```js
// 示例获取设备id为1的设备name信息。 // 获取输入设备id为1的设备信息。
inputDevice.getDevice(1).then((inputDevice)=>{ inputDevice.getDeviceInfo(1).then((deviceData) => {
console.log("The device name is: " + inputDevice.name); console.log(`Device info: ${JSON.stringify(deviceData)}`);
}); });
``` ```
...@@ -332,28 +336,28 @@ inputDevice.getDevice(1).then((inputDevice)=>{ ...@@ -332,28 +336,28 @@ inputDevice.getDevice(1).then((inputDevice)=>{
supportKeys(deviceId: number, keys: Array&lt;KeyCode&gt;, callback: Callback&lt;Array&lt;boolean&gt;&gt;): void supportKeys(deviceId: number, keys: Array&lt;KeyCode&gt;, callback: Callback&lt;Array&lt;boolean&gt;&gt;): void
获取输入设备支持的键码值,使用callback方式作为异步方法 获取输入设备是否支持指定的键码值,使用Callback异步方式返回结果
**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice **系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
**参数** **参数**
| 参数 | 类型 | 必填 | 说明 | | 参数 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------ | ---- | --------------------------------- | | -------- | ------------------------------------ | ---- | ------------------------------------------------------ |
| deviceId | number | 是 | 输入设备的唯一标识,同一个物理设备反复插拔,其设备id会发生变化。 | | deviceId | number | 是 | 输入设备id,同一个物理设备反复插拔,设备id会发生变化。 |
| keys | Array&lt;KeyCode&gt; | 是 | 需要查询的键码值,最多支持5个按键查询。 | | keys | Array&lt;KeyCode&gt; | 是 | 需要查询的键码值,最多支持5个按键查询。 |
| callback | Callback&lt;Array&lt;boolean&gt;&gt; | 是 | 回调函数,异步返回查询结果。 | | callback | Callback&lt;Array&lt;boolean&gt;&gt; | 是 | 回调函数,异步返回查询结果。 |
**示例** **示例**
```js ```js
// 示例查询id为1的设备对于17、22和2055按键的支持情况。 // 查询id为1的输入设备对于17、22和2055按键的支持情况。
try { try {
inputDevice.supportKeys(1, [17, 22, 2055], (error, ret) => { inputDevice.supportKeys(1, [17, 22, 2055], (error, supportResult) => {
console.log("The query result is as follows: " + ret); console.log(`Query result: ${JSON.stringify(supportResult)}`);
}); });
} catch (error) { } catch (error) {
console.info("supportKeys " + error.code + " " + error.message); console.log(`Query failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
...@@ -361,33 +365,33 @@ try { ...@@ -361,33 +365,33 @@ try {
supportKeys(deviceId: number, keys: Array&lt;KeyCode&gt;): Promise&lt;Array&lt;boolean&gt;&gt; supportKeys(deviceId: number, keys: Array&lt;KeyCode&gt;): Promise&lt;Array&lt;boolean&gt;&gt;
获取输入设备支持的键码值,使用Promise方式作为异步方法 获取输入设备是否支持指定的键码值,使用Promise异步方式返回结果
**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice **系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
**参数** **参数**
| 参数 | 类型 | 必填 | 说明 | | 参数 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | --------------------------------- | | -------- | -------------------- | ---- | ------------------------------------------------------ |
| deviceId | number | 是 | 输入设备的唯一标识,同一个物理设备反复插拔,其设备id会发生变化。 | | deviceId | number | 是 | 输入设备id,同一个物理设备反复插拔,设备id会发生变化。 |
| keys | Array&lt;KeyCode&gt; | 是 | 需要查询的键码值,最多支持5个按键查询。 | | keys | Array&lt;KeyCode&gt; | 是 | 需要查询的键码值,最多支持5个按键查询。 |
**返回值** **返回值**
| 参数 | 说明 | | 参数 | 说明 |
| ----------------------------------- | ------------------- | | ----------------------------------- | ------------------------------- |
| Promise&lt;Array&lt;boolean&gt;&gt; | Promise实例,用于异步获取结果。 | | Promise&lt;Array&lt;boolean&gt;&gt; | Promise对象,异步返回查询结果。 |
**示例** **示例**
```js ```js
// 示例查询id为1的设备对于17、22和2055按键的支持情况。 // 查询id为1的输入设备对于17、22和2055按键的支持情况。
try { try {
inputDevice.supportKeys(1, [17, 22, 2055]).then((ret) => { inputDevice.supportKeys(1, [17, 22, 2055]).then((supportResult) => {
console.log("The query result is as follows: " + ret); console.log(`Query result: ${JSON.stringify(supportResult)}`);
}); });
} catch (error) { } catch (error) {
console.info("supportKeys " + error.code + " " + error.message); console.log(`Query failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
...@@ -395,32 +399,31 @@ try { ...@@ -395,32 +399,31 @@ try {
getKeyboardType(deviceId: number, callback: AsyncCallback&lt;KeyboardType&gt;): void getKeyboardType(deviceId: number, callback: AsyncCallback&lt;KeyboardType&gt;): void
查询输入设备的键盘类型,使用callback方式作为异步方法 获取输入设备的键盘类型,使用AsyncCallback异步方式返回结果
**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice **系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
**参数** **参数**
| 参数 | 类型 | 必填 | 说明 | | 参数 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | --------------------------------- | | -------- | --------------------------------------------------- | ---- | ------------------------------------------------------------ |
| deviceId | number | 是 | 输入设备的唯一标识,同一个物理设备反复插拔,其设备id会发生变化。 | | deviceId | number | 是 | 输入设备的唯一标识,同一个物理设备反复插拔,设备id会发生变化。 |
| callback | AsyncCallback&lt;[KeyboardType](#keyboardtype9)&gt; | 是 | 回调函数,异步返回查询结果。 | | callback | AsyncCallback&lt;[KeyboardType](#keyboardtype9)&gt; | 是 | 回调函数,异步返回查询结果。 |
**示例** **示例**
```js ```js
// 示例查询设备id为1的设备键盘类型。 // 查询id为1的输入设备的键盘类型。
try { try {
inputDevice.getKeyboardType(1, (error, number) => { inputDevice.getKeyboardType(1, (error, type) => {
if (error) { if (error) {
console.log(`Failed to get keyboardtype. console.log(`Failed to get keyboard type, error: ${JSON.stringify(error, [`code`, `message`])}`);
error code=${JSON.stringify(err.code)} msg=${JSON.stringify(err.message)}`);
return; return;
} }
console.log("The keyboard type of the device is: " + number); console.log(`Keyboard type: ${JSON.stringify(type)}`);
}); });
} catch (error) { } catch (error) {
console.info("getKeyboardType " + error.code + " " + error.message); console.log(`Failed to get keyboard type, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
...@@ -428,39 +431,45 @@ try { ...@@ -428,39 +431,45 @@ try {
getKeyboardType(deviceId: number): Promise&lt;KeyboardType&gt; getKeyboardType(deviceId: number): Promise&lt;KeyboardType&gt;
查询输入设备的键盘类型,使用Promise方式作为异步方法 获取输入设备的键盘类型,使用AsyncCallback异步方式返回结果
**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice **系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
**参数**
| 参数 | 类型 | 必填 | 说明 |
| -------- | ------ | ---- | ------------------------------------------------------------ |
| deviceId | number | 是 | 输入设备的唯一标识,同一个物理设备反复插拔,设备id会发生变化。 |
**返回值** **返回值**
| 参数 | 说明 | | 参数 | 说明 |
| ---------------------------------------- | ------------------- | | --------------------------------------------- | ------------------------------- |
| Promise&lt;[KeyboardType](#keyboardtype9)&gt; | Promise实例,用于异步获取结果。 | | Promise&lt;[KeyboardType](#keyboardtype9)&gt; | Promise对象,异步返回查询结果。 |
**示例** **示例**
```js ```js
// 示例查询设备id为1的设备键盘类型。 // 示例查询设备id为1的设备键盘类型。
try { try {
inputDevice.getKeyboardType(1).then((number) => { inputDevice.getKeyboardType(1).then((type) => {
console.log("The keyboard type of the device is: " + number); console.log(`Keyboard type: ${JSON.stringify(type)}`);
}); });
} catch (error) { } catch (error) {
console.info("getKeyboardType " + error.code + " " + error.message); console.log(`Failed to get keyboard type, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
## DeviceListener<sup>9+</sup> ## DeviceListener<sup>9+</sup>
输入设备的描述信息。 输入设备热插拔的描述信息。
**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice **系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
| 名称 | 参数类型 | 说明 | | 名称 | 参数类型 | 说明 |
| -------- | --------------------------- | --------------------------------- | | -------- | --------------------------- | ------------------------------------------------------------ |
| type | [ChangedType](#changedtype) | 表示输入设备插入或者移除。 | | type | [ChangedType](#changedtype) | 输入设备插入或者移除。 |
| deviceId | number | 输入设备的唯一标识,同一个物理设备反复插拔,设备id会发生变化。 | | deviceId | number | 输入设备的唯一标识,同一个物理设备反复插拔,设备id会发生变化。 |
## InputDeviceData ## InputDeviceData
...@@ -468,18 +477,18 @@ try { ...@@ -468,18 +477,18 @@ try {
**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice **系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
| 名称 | 参数类型 | 说明 | | 名称 | 参数类型 | 说明 |
| -------------------- | -------------------------------------- | ---------------------------------------- | | -------------------- | -------------------------------------- | ------------------------------------------------------------ |
| id | number | 输入设备的唯一标识,同一个物理设备反复插拔,其设备id会发生变化。 | | id | number | 输入设备的唯一标识,同一个物理设备反复插拔,设备id会发生变化。 |
| name | string | 输入设备的名字。 | | name | string | 输入设备的名字。 |
| sources | Array&lt;[SourceType](#sourcetype)&gt; | 输入设备支持的源类型。比如有的键盘上附带触摸板,则此设备有keyboard和touchpad两种输入源。 | | sources | Array&lt;[SourceType](#sourcetype)&gt; | 输入设备支持的源类型。比如有的键盘上附带触摸板,则此设备有keyboard和touchpad两种输入源。 |
| axisRanges | Array&lt;[axisRanges](#axisrange)&gt; | 输入设备的轴信息。 | | axisRanges | Array&lt;[axisRanges](#axisrange)&gt; | 输入设备的轴信息。 |
| bus<sup>9+</sup> | number | 输入设备的总线类型。 | | bus<sup>9+</sup> | number | 输入设备的总线类型。 |
| product<sup>9+</sup> | number | 输入设备的产品信息。 | | product<sup>9+</sup> | number | 输入设备的产品信息。 |
| vendor<sup>9+</sup> | number | 输入设备的厂商信息。 | | vendor<sup>9+</sup> | number | 输入设备的厂商信息。 |
| version<sup>9+</sup> | number | 输入设备的版本信息。 | | version<sup>9+</sup> | number | 输入设备的版本信息。 |
| phys<sup>9+</sup> | string | 输入设备的物理地址。 | | phys<sup>9+</sup> | string | 输入设备的物理地址。 |
| uniq<sup>9+</sup> | string | 输入设备的唯一标识。 | | uniq<sup>9+</sup> | string | 输入设备的唯一标识。 |
## AxisType<sup>9+</sup> ## AxisType<sup>9+</sup>
...@@ -517,7 +526,7 @@ try { ...@@ -517,7 +526,7 @@ try {
## SourceType ## SourceType
定义这个轴的输入源类型。比如鼠标设备可上报x轴事件,则x轴的源就是鼠标。 轴的输入源类型。比如鼠标设备可上报x轴事件,则x轴的输入源就是鼠标。
**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice **系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
......
# 鼠标指针 # 鼠标指针
鼠标指针管理模块,用于提供鼠标指针相关属性接口 鼠标指针管理模块,用于查询和设置鼠标指针相关属性
> **说明**: > **说明**:
> >
...@@ -12,11 +12,11 @@ ...@@ -12,11 +12,11 @@
import pointer from '@ohos.multimodalInput.pointer'; import pointer from '@ohos.multimodalInput.pointer';
``` ```
## pointer.setPointerVisibele<sup>9+</sup> ## pointer.setPointerVisible<sup>9+</sup>
setPointerVisible(visible: boolean, callback: AsyncCallback&lt;void&gt;): void setPointerVisible(visible: boolean, callback: AsyncCallback&lt;void&gt;): void
设置鼠标指针显示或者隐藏,使用callback异步回调 设置鼠标指针显示或者隐藏,使用AsyncCallback异步方式返回结果
**系统能力**:SystemCapability.MultimodalInput.Input.Pointer **系统能力**:SystemCapability.MultimodalInput.Input.Pointer
...@@ -24,18 +24,22 @@ setPointerVisible(visible: boolean, callback: AsyncCallback&lt;void&gt;): void ...@@ -24,18 +24,22 @@ setPointerVisible(visible: boolean, callback: AsyncCallback&lt;void&gt;): void
| 参数 | 类型 | 必填 | 说明 | | 参数 | 类型 | 必填 | 说明 |
| -------- | ------------------------- | ---- | ---------------------------------------- | | -------- | ------------------------- | ---- | ---------------------------------------- |
| visible | boolean | 是 | 鼠标指针显示或者隐藏状态,true: 鼠标指针显示; false: 鼠标指针隐藏。 | | visible | boolean | 是 | 鼠标指针是否显示。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当设置鼠标显示或隐藏成功,err为undefined,否则为错误对象。 | | callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
**示例** **示例**
```js ```js
try { try {
pointer.setPointerVisible(true, (err, data) => { 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 (err) { } catch (error) {
console.log(`Set pointer visible failed. err=${JSON.stringify(err)}, msg=${JSON.stringify(message)}`); console.log(`Set pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
...@@ -43,7 +47,7 @@ try { ...@@ -43,7 +47,7 @@ try {
setPointerVisible(visible: boolean): Promise&lt;void&gt; setPointerVisible(visible: boolean): Promise&lt;void&gt;
设置鼠标指针显示或者隐藏,使用Promise方式作为异步方法 设置鼠标指针显示或者隐藏,使用Promise异步方式返回结果
**系统能力**:SystemCapability.MultimodalInput.Input.Pointer **系统能力**:SystemCapability.MultimodalInput.Input.Pointer
...@@ -51,23 +55,23 @@ setPointerVisible(visible: boolean): Promise&lt;void&gt; ...@@ -51,23 +55,23 @@ setPointerVisible(visible: boolean): Promise&lt;void&gt;
| 参数 | 类型 | 必填 | 说明 | | 参数 | 类型 | 必填 | 说明 |
| ------- | ------- | ---- | ---------------------------------------- | | ------- | ------- | ---- | ---------------------------------------- |
| visible | boolean | 是 | 鼠标指针显示或者隐藏状态,true: 鼠标指针显示; false: 鼠标指针隐藏。 | | visible | boolean | 是 | 鼠标指针是否显示。 |
**返回值** **返回值**
| 参数 | 说明 | | 参数 | 说明 |
| ------------------- | ------------------- | | ------------------- | ------------------- |
| Promise&lt;void&gt; | Promise实例,用于异步获取结果。 | | Promise&lt;void&gt; | Promise对象。 |
**示例** **示例**
```js ```js
try { try {
pointer.setPointerVisible(false).then(data => { pointer.setPointerVisible(false).then(() => {
console.log(`Set mouse pointer visible success`); console.log(`Set pointer visible success`);
}); });
} catch { } catch (error) {
console.log(`Set mouse pointer visible failed err=${JSON.stringify(data)}, msg=${JSON.stringify(message)}`); console.log(`Set pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
...@@ -75,7 +79,7 @@ try { ...@@ -75,7 +79,7 @@ try {
isPointerVisible(callback: AsyncCallback&lt;boolean&gt;): void isPointerVisible(callback: AsyncCallback&lt;boolean&gt;): void
获取鼠标指针显示或隐藏状态,使用callback异步回调 获取鼠标指针显示或隐藏状态,使用AsyncCallback异步方式返回结果
**系统能力**:SystemCapability.MultimodalInput.Input.Pointer **系统能力**:SystemCapability.MultimodalInput.Input.Pointer
...@@ -83,17 +87,21 @@ isPointerVisible(callback: AsyncCallback&lt;boolean&gt;): void ...@@ -83,17 +87,21 @@ isPointerVisible(callback: AsyncCallback&lt;boolean&gt;): void
| 参数 | 类型 | 必填 | 说明 | | 参数 | 类型 | 必填 | 说明 |
| -------- | ---------------------------- | ---- | -------------- | | -------- | ---------------------------- | ---- | -------------- |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数,异步返回查询结果。 | | callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数,异步返回鼠标指针显示或隐藏状态。 |
**示例** **示例**
```js ```js
try { try {
pointer.isPointerVisible(visible, (err, data) => { pointer.isPointerVisible((error, visible) => {
console.log(`The mouse pointer visible attributes is ` + 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 (err) { } catch (error) {
console.log(`The mouse pointer visible attributes is failed. err=${JSON.stringify(err)}, msg=${JSON.stringify(message)}`); console.log(`Get pointer visible failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
...@@ -101,7 +109,7 @@ try { ...@@ -101,7 +109,7 @@ try {
isPointerVisible(): Promise&lt;boolean&gt; isPointerVisible(): Promise&lt;boolean&gt;
获取鼠标指针显示或隐藏状态,使用Promise方式作为异步方法 获取鼠标指针显示或隐藏状态,使用Promise异步方式返回结果
**系统能力**:SystemCapability.MultimodalInput.Input.Pointer **系统能力**:SystemCapability.MultimodalInput.Input.Pointer
...@@ -109,25 +117,21 @@ isPointerVisible(): Promise&lt;boolean&gt; ...@@ -109,25 +117,21 @@ isPointerVisible(): Promise&lt;boolean&gt;
| 参数 | 说明 | | 参数 | 说明 |
| ---------------------- | ------------------- | | ---------------------- | ------------------- |
| Promise&lt;boolean&gt; | Promise实例,用于异步获取结果。 | | Promise&lt;boolean&gt; | Promise对象,异步返回鼠标指针显示或隐藏状态。 |
**示例** **示例**
```js ```js
try { pointer.isPointerVisible().then((visible) => {
pointer.isPointerVisible().then((data) => { console.log(`Get pointer visible success, visible: ${JSON.stringify(visible)}`);
console.log(`The mouse pointer visible attributes is success. data=${JSON.stringify(data)}`); });
});
} catch (err) {
ponsole.info(`The mouse pointer visible attributes is failed. err=${JSON.stringify(err)}, msg=${JSON.stringify(message)}`);
}
``` ```
## pointer.setPointerSpeed<sup>9+</sup> ## pointer.setPointerSpeed<sup>9+</sup>
setPointerSpeed(speed: number, callback: AsyncCallback&lt;void&gt;): void setPointerSpeed(speed: number, callback: AsyncCallback&lt;void&gt;): void
设置鼠标移动速度,使用callback异步回调 设置鼠标移动速度,使用AsyncCallback异步方式返回结果
**系统能力**:SystemCapability.MultimodalInput.Input.Pointer **系统能力**:SystemCapability.MultimodalInput.Input.Pointer
...@@ -135,18 +139,22 @@ setPointerSpeed(speed: number, callback: AsyncCallback&lt;void&gt;): void ...@@ -135,18 +139,22 @@ setPointerSpeed(speed: number, callback: AsyncCallback&lt;void&gt;): void
| 参数 | 类型 | 必填 | 说明 | | 参数 | 类型 | 必填 | 说明 |
| -------- | ------------------------- | ---- | ------------------------------------- | | -------- | ------------------------- | ---- | ------------------------------------- |
| speed | number | 是 | 鼠标移动速度设置挡位值1-11,最大值:11,最小值:1,标准值:5。 | | speed | number | 是 | 鼠标移动速度,范围1-11,默认为5。 |
| callback | AysncCallback&lt;void&gt; | 是 | 回调函数。当设置鼠标速度成功,err为undefined,否则为错误对象。 | | callback | AysncCallback&lt;void&gt; | 是 | 回调函数。 |
**示例** **示例**
```js ```js
try { try {
pointer.setPointerSpeed(5, (err, data) => { 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`); console.log(`Set pointer speed success`);
}); });
} catch (err) { } catch (err) {
console.log(`Set pointer speed failed. err=${JSON.stringify(err)}, msg=${JSON.stringify(message)}`); console.log(`Set pointer speed failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
...@@ -154,7 +162,7 @@ try { ...@@ -154,7 +162,7 @@ try {
setPointerSpeed(speed: number): Promise&lt;void&gt; setPointerSpeed(speed: number): Promise&lt;void&gt;
设置鼠标移动速度,使用Promise异步回调 设置鼠标移动速度,使用Promise异步方式返回结果
**系统能力**:SystemCapability.MultimodalInput.Input.Pointer **系统能力**:SystemCapability.MultimodalInput.Input.Pointer
...@@ -162,23 +170,23 @@ setPointerSpeed(speed: number): Promise&lt;void&gt; ...@@ -162,23 +170,23 @@ setPointerSpeed(speed: number): Promise&lt;void&gt;
| 参数 | 类型 | 必填 | 说明 | | 参数 | 类型 | 必填 | 说明 |
| ----- | ------ | ---- | ----------------------------------- | | ----- | ------ | ---- | ----------------------------------- |
| speed | number | 是 | 鼠标移动速度设置挡位值1-11,最大值:11,最小值:1,标准值:5。 | | speed | number | 是 | 鼠标移动速度,范围1-11,默认为5。 |
**返回值** **返回值**
| 参数 | 说明 | | 参数 | 说明 |
| ------------------- | ---------------- | | ------------------- | ---------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 | | Promise&lt;void&gt; | Promise对象。 |
**示例** **示例**
```js ```js
try { try {
pointer.setPointerSpeed(5).then(data => { pointer.setPointerSpeed(5).then(() => {
console.log(`Set pointer speed success`); console.log(`Set pointer speed success`);
}); });
} catch (err) { } catch (error) {
console.log(`Set pointer speed failed err=${JSON.stringify(err)}, msg=${JSON.stringify(message)}`); console.log(`Set pointer speed failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
...@@ -186,7 +194,7 @@ try { ...@@ -186,7 +194,7 @@ try {
getPointerSpeed(callback: AsyncCallback&lt;number&gt;): void getPointerSpeed(callback: AsyncCallback&lt;number&gt;): void
获取当前鼠标移动速度,使用callback异步回调 获取鼠标移动速度,使用AsyncCallback异步方式返回结果
**系统能力**:SystemCapability.MultimodalInput.Input.Pointer **系统能力**:SystemCapability.MultimodalInput.Input.Pointer
...@@ -194,17 +202,21 @@ getPointerSpeed(callback: AsyncCallback&lt;number&gt;): void ...@@ -194,17 +202,21 @@ getPointerSpeed(callback: AsyncCallback&lt;number&gt;): void
| 参数 | 类型 | 必填 | 说明 | | 参数 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | -------------- | | -------- | --------------------------- | ---- | -------------- |
| callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,异步返回查询结果。 | | callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,异步返回鼠标移动速度。 |
**示例** **示例**
```js ```js
try { try {
pointer.getPointerSpeed(speed, (err, data) => { pointer.getPointerSpeed(speed, (error, speed) => {
console.log(`The pointer speed is ` + 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 (err) { } catch (err) {
console.log(`Failed to get the pointer speed. err=${JSON.stringify(err)}, msg=${JSON.stringify(message)}`); console.log(`Get pointer speed failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
...@@ -212,7 +224,7 @@ try { ...@@ -212,7 +224,7 @@ try {
getPointerSpeed(): Promise&lt;number&gt; getPointerSpeed(): Promise&lt;number&gt;
获取当前鼠标移动速度,使用Promise异步回调 获取当前鼠标移动速度,使用Promise异步方式返回结果
**系统能力**:SystemCapability.MultimodalInput.Input.Pointer **系统能力**:SystemCapability.MultimodalInput.Input.Pointer
...@@ -220,17 +232,17 @@ getPointerSpeed(): Promise&lt;number&gt; ...@@ -220,17 +232,17 @@ getPointerSpeed(): Promise&lt;number&gt;
| 参数 | 说明 | | 参数 | 说明 |
| --------------------- | ------------------- | | --------------------- | ------------------- |
| Promise&lt;number&gt; | Promise实例,用于异步获取结果。 | | Promise&lt;number&gt; | Promise实例,异步返回鼠标移动速度。 |
**示例** **示例**
```js ```js
try { try {
pointer.getPointerSpeed().then(data => { pointer.getPointerSpeed().then(speed => {
console.log(`Get pointer speed success. data=${JSON.stringify(data)}`); console.log(`Get pointer speed success, speed: ${JSON.stringify(speed)}`);
}); });
} catch (err) { } catch (error) {
console.log(`Get pointer speed failed err=${JSON.stringify(err)}, msg=${JSON.stringify(message)}`); console.log(`Get pointer speed failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
``` ```
...@@ -238,7 +250,7 @@ try { ...@@ -238,7 +250,7 @@ try {
getPointerStyle(windowId: number, callback: AsyncCallback&lt;PointerStyle&gt;): void getPointerStyle(windowId: number, callback: AsyncCallback&lt;PointerStyle&gt;): void
获取鼠标样式类型,使用callback异步回调 获取鼠标样式类型,使用AsyncCallback异步方式返回结果
**系统能力**:SystemCapability.MultimodalInput.Input.Pointer **系统能力**:SystemCapability.MultimodalInput.Input.Pointer
...@@ -246,29 +258,27 @@ getPointerStyle(windowId: number, callback: AsyncCallback&lt;PointerStyle&gt;): ...@@ -246,29 +258,27 @@ getPointerStyle(windowId: number, callback: AsyncCallback&lt;PointerStyle&gt;):
| 参数 | 类型 | 必填 | 说明 | | 参数 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | -------------- | | -------- | ---------------------------------------- | ---- | -------------- |
| windowId | number | 是 | 输入设备的窗口id。 | | windowId | number | 是 | 窗口id。 |
| callback | AsyncCallback&lt;[PointerStyle](#pointerstyle9)&gt; | 是 | 回调函数,异步返回查询结果。 | | callback | AsyncCallback&lt;[PointerStyle](#pointerstyle9)&gt; | 是 | 回调函数,异步返回鼠标样式类型。 |
**示例** **示例**
```js ```js
// 获取设备的鼠标样式。
import window from '@ohos.window'; import window from '@ohos.window';
var windowClass = null;
window.getTopWindow((err, data) => { window.getTopWindow((error, win) => {
windowClass = data; win.getProperties((error, properties) => {
windowClass.getProperties((err, data) => { var windowId = properties.id;
var windowId = data.id;
if (windowId < 0) { if (windowId < 0) {
console.log(`Invalid windowId`); console.log(`Invalid windowId`);
return; return;
} }
try { try {
pointer.getPointerStyle(windowId, (err, ret) => { pointer.getPointerStyle(windowId, (error, style) => {
console.log(`The mouse pointer style is: ` + ret); console.log(`Get pointer style success, style: ${JSON.stringify(style)}`);
}); });
} catch (err) { } catch (error) {
console.log(`Failed to get the pointer style. err=${JSON.stringify(err)}, msg=${JSON.stringify(message)}`); console.log(`Get pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
}); });
}); });
...@@ -278,7 +288,7 @@ window.getTopWindow((err, data) => { ...@@ -278,7 +288,7 @@ window.getTopWindow((err, data) => {
getPointerStyle(windowId: number): Promise&lt;PointerStyle&gt; getPointerStyle(windowId: number): Promise&lt;PointerStyle&gt;
获取鼠标样式类型,使用Promise方式作为异步方法 获取鼠标样式类型,使用Promise异步方式返回结果
**系统能力**:SystemCapability.MultimodalInput.Input.Pointer **系统能力**:SystemCapability.MultimodalInput.Input.Pointer
...@@ -286,28 +296,26 @@ getPointerStyle(windowId: number): Promise&lt;PointerStyle&gt; ...@@ -286,28 +296,26 @@ getPointerStyle(windowId: number): Promise&lt;PointerStyle&gt;
| 参数 | 说明 | | 参数 | 说明 |
| ---------------------------------------- | ------------------- | | ---------------------------------------- | ------------------- |
| Promise&lt;[PointerStyle](#pointerstyle9)&gt; | Promise实例,用于异步获取结果。 | | Promise&lt;[PointerStyle](#pointerstyle9)&gt; | Promise实例,异步返回鼠标样式类型。 |
**示例** **示例**
```js ```js
// 获取设备的鼠标样式。
import window from '@ohos.window'; import window from '@ohos.window';
var windowClass = null;
window.getTopWindow((err, data) => { window.getTopWindow((error, win) => {
windowClass = data; win.getProperties((error, properties) => {
windowClass.getProperties((err, data) => { var windowId = properties.id;
var windowId = data.id;
if (windowId < 0) { if (windowId < 0) {
console.log(`Invalid windowId`); console.log(`Invalid windowId`);
return; return;
} }
try { try {
pointer.getPointerStyle(windowId).then((ret) => { pointer.getPointerStyle(windowId).then((style) => {
console.log(`The mouse pointer style is: ` + ret); console.log(`Get pointer style success, style: ${JSON.stringify(style)}`);
}); });
} catch (err) { } catch (error) {
console.log(`Get pointer style failed err=${JSON.stringify(err)}, msg=${JSON.stringify(message)}`); console.log(`Get pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
}); });
}); });
...@@ -317,7 +325,7 @@ window.getTopWindow((err, data) => { ...@@ -317,7 +325,7 @@ window.getTopWindow((err, data) => {
setPointerStyle(windowId: number, pointerStyle: PointerStyle, callback: AsyncCallback&lt;void&gt;): void setPointerStyle(windowId: number, pointerStyle: PointerStyle, callback: AsyncCallback&lt;void&gt;): void
设置鼠标的样式类型,使用callback异步回调 设置鼠标样式类型,使用AsyncCallback异步方式返回结果
**系统能力**:SystemCapability.MultimodalInput.Input.Pointer **系统能力**:SystemCapability.MultimodalInput.Input.Pointer
...@@ -325,30 +333,28 @@ setPointerStyle(windowId: number, pointerStyle: PointerStyle, callback: AsyncCal ...@@ -325,30 +333,28 @@ setPointerStyle(windowId: number, pointerStyle: PointerStyle, callback: AsyncCal
| 参数 | 类型 | 必填 | 说明 | | 参数 | 类型 | 必填 | 说明 |
| ------------ | ------------------------------ | ---- | ----------------------------------- | | ------------ | ------------------------------ | ---- | ----------------------------------- |
| windowId | number | 是 | 输入设备的窗口id。 | | windowId | number | 是 | 窗口id。 |
| pointerStyle | [PointerStyle](#pointerstyle9) | 是 | 鼠标样式id。 | | pointerStyle | [PointerStyle](#pointerstyle9) | 是 | 鼠标样式id。 |
| callback | AysncCallback&lt;void&gt; | 是 | 回调函数。当设置样式成功,err为undefined,否则为错误对象。 | | callback | AysncCallback&lt;void&gt; | 是 | 回调函数。 |
**示例** **示例**
```js ```js
// 设置设备的鼠标样式。
import window from '@ohos.window'; import window from '@ohos.window';
var windowClass = null;
window.getTopWindow((err, data) => { window.getTopWindow((error, win) => {
windowClass = data; win.getProperties((error, properties) => {
windowClass.getProperties((err, data) => { var windowId = properties.id;
var windowId = data.id;
if (windowId < 0) { if (windowId < 0) {
console.log(`Invalid windowId`); console.log(`Invalid windowId`);
return; return;
} }
try { try {
pointer.setPointerStyle(windowId, pointer.PointerStyle.CROSS, (err) => { pointer.setPointerStyle(windowId, pointer.PointerStyle.CROSS, error => {
console.log(`Successfully set mouse pointer style`); console.log(`Set pointer style success`);
}); });
} catch (err) { } catch (error) {
console.log(`Failed to set the pointer style. err=${JSON.stringify(err)}, msg=${JSON.stringify(message)}`); console.log(`Set pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
}); });
}); });
...@@ -357,7 +363,7 @@ window.getTopWindow((err, data) => { ...@@ -357,7 +363,7 @@ window.getTopWindow((err, data) => {
setPointerStyle(windowId: number, pointerStyle: PointerStyle): Promise&lt;void&gt; setPointerStyle(windowId: number, pointerStyle: PointerStyle): Promise&lt;void&gt;
设置鼠标的样式类型,使用Promise方式作为异步方法 设置鼠标样式类型,使用Promise异步方式返回结果
**系统能力**:SystemCapability.MultimodalInput.Input.Pointer **系统能力**:SystemCapability.MultimodalInput.Input.Pointer
...@@ -365,37 +371,35 @@ setPointerStyle(windowId: number, pointerStyle: PointerStyle): Promise&lt;void&g ...@@ -365,37 +371,35 @@ setPointerStyle(windowId: number, pointerStyle: PointerStyle): Promise&lt;void&g
| 参数 | 类型 | 必填 | 说明 | | 参数 | 类型 | 必填 | 说明 |
| ------------------- | ------------------------------ | ---- | ---------------- | | ------------------- | ------------------------------ | ---- | ---------------- |
| windowId | number | 是 | 输入设备的窗口id。 | | windowId | number | 是 | 窗口id。 |
| pointerStyle | [PointerStyle](#pointerstyle9) | 是 | 鼠标样式id。 | | pointerStyle | [PointerStyle](#pointerstyle9) | 是 | 鼠标样式id。 |
| Promise&lt;void&gt; | void | 是 | 无返回结果的Promise对象。 | | Promise&lt;void&gt; | void | 是 | Promise对象。 |
**示例** **示例**
```js ```js
// 设置设备的鼠标样式。
import window from '@ohos.window'; import window from '@ohos.window';
var windowClass = null;
window.getTopWindow((err, data) => { window.getTopWindow((error, win) => {
windowClass = data; win.getProperties((error, properties) => {
windowClass.getProperties((err, data) => { var windowId = properties.id;
var windowId = data.id;
if (windowId < 0) { if (windowId < 0) {
console.log(`Invalid windowId`); console.log(`Invalid windowId`);
return; return;
} }
try { try {
pointer.setPointerStyle(windowId, pointer.PointerStyle.CROSS).then(() => { pointer.setPointerStyle(windowId, pointer.PointerStyle.CROSS).then(() => {
console.log(`Successfully set mouse pointer style`); console.log(`Set pointer style success`);
}); });
} catch (err) { } catch (error) {
console.log(`Failed to set the pointer style. err=${JSON.stringify(err)}, msg=${JSON.stringify(message)}`); console.log(`Set pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
} }
}); });
}); });
``` ```
## PointerStyle<sup>9+</sup> ## PointerStyle<sup>9+</sup>
定义鼠标样式类型。 鼠标样式类型。
**系统能力**:SystemCapability.MultimodalInput.Input.Pointer **系统能力**:SystemCapability.MultimodalInput.Input.Pointer
...@@ -439,6 +443,4 @@ window.getTopWindow((err, data) => { ...@@ -439,6 +443,4 @@ window.getTopWindow((err, data) => {
| MIDDLE_BTN_NORTH_WEST | 35 | 向西北滚动 | | MIDDLE_BTN_NORTH_WEST | 35 | 向西北滚动 |
| MIDDLE_BTN_SOUTH_EAST | 36 | 向东南滚动 | | MIDDLE_BTN_SOUTH_EAST | 36 | 向东南滚动 |
| MIDDLE_BTN_SOUTH_WEST | 37 | 向西南滚动 | | MIDDLE_BTN_SOUTH_WEST | 37 | 向西南滚动 |
| MIDDLE_BTN_NORTH_SOUTH_WEST_EAST | 38 | 四向锥形移动 | | MIDDLE_BTN_NORTH_SOUTH_WEST_EAST | 38 | 四向锥形移动 |
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册