提交 accbd6fb 编写于 作者: H hungry_feiwei

inputdevice add an interface

Signed-off-by: Nhungry_feiwei <huxiao31@huawei.com>
上级 0ef49cc1
......@@ -15,7 +15,7 @@
import inputDevice from '@ohos.multimodalInput.inputDevice';
```
## inputDevice.on
## inputDevice.on<sup>9+</sup>
on(type: “change”, listener: Callback&lt;DeviceListener&gt;): void
......@@ -33,17 +33,12 @@ on(type: “change”, listener: Callback&lt;DeviceListener&gt;): void
**示例:**
```js
export default {
callback: function(type, deviceId) {
console.log("type: " + type + ", deviceId: " + deviceId)
}
testOn: function() {
inputDevice.on("change", this.callback)
}
}
inputDevice.on("change", (callback)=>{
console.log("type: " + callback.type + ", deviceId: " + callback.deviceId);
});
```
## inputDevice.off
## inputDevice.off<sup>9+</sup>
on(type: “change”, listener?: Callback&lt;DeviceListener&gt;): void
......@@ -61,18 +56,7 @@ on(type: “change”, listener?: Callback&lt;DeviceListener&gt;): void
**示例:**
```js
export default {
callback: function(type, deviceId) {
console.log("type: " + type + ", deviceId: " + deviceId)
}
testOff: function() {
// 取消特定监听
inputDevice.off("change", this.callback)
// 取消所有监听
inputDevice.off("change")
}
}
inputDevice.off("change");
```
## inputDevice.getDeviceIds
......@@ -92,19 +76,9 @@ getDeviceIds(callback: AsyncCallback&lt;Array&lt;number&gt;&gt;): void
**示例:**
```js
export default {
data: {
deviceIds: Array,
},
callback: function(ids) {
this.deviceIds = ids;
},
testGetDeviceIds: function () {
console.info("InputDeviceJsTest---start---testGetDeviceIds");
inputDevice.getDeviceIds(this.callback);
console.info("InputDeviceJsTest---end---testGetDeviceIds");
}
}
inputDevice.getDeviceIds((ids)=>{
console.log("The device ID list is: " + ids);
});
```
## inputDevice.getDeviceIds
......@@ -124,17 +98,9 @@ function getDeviceIds(): Promise&lt;&lt;Array&lt;number&gt;&gt;
**示例:**
```js
export default {
testGetDeviceIds: function () {
console.info("InputDeviceJsTest---start---testGetDeviceIds");
let promise = inputDevice.getDeviceIds();
promise.then((data)=> {
console.info('GetDeviceIds successed, Data: ' + JSON.stringify(data))
}).catch((err)=>{
console.error('Failed GetDeviceIds. Cause: ' + JSON.stringify(err));
});
}
}
inputDevice.getDeviceIds().then((ids)=>{
console.log("The device ID list is: " + ids);
});
```
## inputDevice.getDevice
......@@ -155,23 +121,10 @@ getDevice(deviceId: number, callback: AsyncCallback&lt;InputDeviceData&gt;): voi
**示例:**
```js
export default {
InputDeviceData: {
deviceId : 0,
name : "NA",
sources : Array,
axisRanges : Array,
},
callback: function(deviceData) {
this.InputDeviceData = deviceData;
},
testGetDevice: function () {
// 示例获取设备id为1的设备信息。
console.info("InputDeviceJsTest---start---testGetDevice");
inputDevice.getDevice(1, this.callback);
console.info("InputDeviceJsTest---end---testGetDevice");
}
}
// 示例获取设备id为1的设备name信息。
inputDevice.getDevice(1, (inputDevice)=>{
console.log("The device name is: " + inputDevice.name);
});
```
## inputDevice.getDevice
......@@ -197,27 +150,13 @@ function getDevice(deviceId: number): Promise&lt;InputDeviceData&gt;
**示例:**
```js
export default {
InputDeviceData: {
deviceId : 0,
name : "NA",
sources : Array,
axisRanges : Array,
},
testGetDevice: function () {
// 示例获取设备id为1的设备信息。
console.info("InputDeviceJsTest---start---testGetDevice");
let promise = inputDevice.getDevice(1);
promise.then((data)=> {
console.info('GetDeviceId successed, Data: ' + JSON.stringify(data))
}).catch((err)=>{
console.error('Failed GetDeviceId. Cause: ' + JSON.stringify(err));
});
}
}
// 示例获取设备id为1的设备name信息。
inputDevice.getDevice(1).then((inputDevice)=>{
console.log("The device name is: " + inputDevice.name);
});
```
## inputDevice.supportKeys
## inputDevice.supportKeys<sup>9+</sup>
supportKeys(deviceId: number, keys: Array&lt;KeyCode&gt;, callback: Callback&lt;Array&lt;boolean&gt;&gt;): void;
......@@ -236,18 +175,13 @@ supportKeys(deviceId: number, keys: Array&lt;KeyCode&gt;, callback: Callback&lt;
**示例:**
```js
export default {
callback: function(ret) {
console.log("The query result is as follows: " + ret);
},
testSupportKeys: function() {
// 示例查询id为1的设备对于17、22和2055按键的支持情况。
inputDevice.supportKeys(1, [17, 22, 2055], this.callback);
}
}
// 示例查询id为1的设备对于17、22和2055按键的支持情况。
inputDevice.supportKeys(1, [17, 22, 2055], (ret)=>{
console.log("The query result is as follows: " + ret);
});
```
## inputDevice.supportKeys
## inputDevice.supportKeys<sup>9+</sup>
supportKeys(deviceId: number, keys: Array&lt;KeyCode&gt;): Promise&lt;Array&lt;boolean&gt;&gt;
......@@ -271,130 +205,13 @@ supportKeys(deviceId: number, keys: Array&lt;KeyCode&gt;): Promise&lt;Array&lt;b
**示例:**
```js
export default {
testSupportKeys: function() {
// 示例查询id为1的设备对于17、22和2055按键的支持情况。
inputDevice.supportKeys(1, [17, 22, 2055]).then((ret)=>{
console.log("The query result is as follows: " + ret);
})
}
}
// 示例查询id为1的设备对于17、22和2055按键的支持情况。
inputDevice.supportKeys(1, [17, 22, 2055]).then((ret)=>{
console.log("The query result is as follows: " + ret);
})
```
## inputDevice.setPointerSpeed
setPointerSpeed(speed: number, callback: AsyncCallback&lt;void&gt;): void;
设置光标移动的速度,使用callback方式作为异步方法。
**系统能力:** SystemCapability.MultimodalInput.Input.InputDevice
**参数:**
| 参数 | 类型 | 必填 | 说明 |
| -------- | -------------------------------------- | ---- | ---------------- |
| speed | number | 是 | 光标移动的速度。 |
| callback | AsyncCallback&lt;Array&lt;void&gt;&gt; | 是 | 回调函数。 |
**示例:**
```js
export default {
callback: function() {
console.log("The callback function is called.");
},
testSetPointerSpeed: function() {
inputDevice.setPointerSpeed(100, this.callback);
}
}
```
## inputDevice.setPointerSpeed
setPointerSpeed(speed: number): Promise&lt;void&gt;
设置光标移动的速度,使用Promise方式作为异步方法。
**系统能力:** SystemCapability.MultimodalInput.Input.InputDevice
**参数:**
| 参数 | 类型 | 必填 | 说明 |
| ----- | ------ | ---- | ---------------- |
| speed | number | 是 | 光标移动的速度。 |
**返回值:**
| 参数 | 说明 |
| ------------------- | ----------------------------- |
| Promise&lt;void&gt; | Promise实例,用于异步获取结果 |
**示例:**
```js
export default {
testSetPointerSpeed: function() {
inputDevice.setPointerSpeed(100).then(()=>{
console.log("The callback function is called.");
})
}
}
```
## inputDevice.getPointerSpeed
getPointerSpeed(callback: AsyncCallback&lt;number&gt;): void;
获取光标移动的速度,使用callback方式作为异步方法。
**系统能力:** SystemCapability.MultimodalInput.Input.InputDevice
**参数:**
| 参数 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ---------------------------- |
| callback | AsyncCallback&lt;number&gt; | 是 | 回调函数,异步返回查询结果。 |
**示例:**
```js
export default {
callback: function(ret) {
console.log("The cursor movement speed is: " + ret);
},
testGetPointerSpeed: function() {
inputDevice.getPointerSpeed(this.callback);
}
}
```
## inputDevice.getPointerSpeed
getPointerSpeed(): Promise&lt;number&gt;
获取光标移动的速度,使用Promise方式作为异步方法。
**系统能力:** SystemCapability.MultimodalInput.Input.InputDevice
**返回值:**
| 参数 | 说明 |
| --------------------- | ----------------------------- |
| Promise&lt;number&gt; | Promise实例,用于异步获取结果 |
**示例:**
```js
export default {
testGetPointerSpeed: function() {
inputDevice.getPointerSpeed().then((ret)=>{
console.log("The cursor movement speed is: " + ret);
})
}
}
```
## inputDevice.getKeyboardType
## inputDevice.getKeyboardType<sup>9+</sup>
getKeyboardType(deviceId: number, callback: AsyncCallback&lt;KeyboardType&gt;): void;
......@@ -412,18 +229,13 @@ getKeyboardType(deviceId: number, callback: AsyncCallback&lt;KeyboardType&gt;):
**示例:**
```js
export default {
callback: function(ret) {
console.log("The keyboard type of the device is: " + ret);
},
testGetKeyboardType: function() {
// 示例查询设备id为1的设备键盘类型。
inputDevice.getKeyboardType(1, this.callback);
}
}
// 示例查询设备id为1的设备键盘类型。
inputDevice.getKeyboardType(1, (ret)=>{
console.log("The keyboard type of the device is: " + ret);
});
```
## inputDevice.getKeyboardType
## inputDevice.getKeyboardType<sup>9+</sup>
getKeyboardType(deviceId: number,): Promise&lt;KeyboardType&gt;
......@@ -440,16 +252,13 @@ getKeyboardType(deviceId: number,): Promise&lt;KeyboardType&gt;;
**示例:**
```js
export default {
testGetKeyboardType: function() {
inputDevice.getKeyboardType().then((ret)=>{
console.log("The keyboard type of the device is: " + ret);
})
}
}
// 示例查询设备id为1的设备键盘类型。
inputDevice.getKeyboardType().then((ret)=>{
console.log("The keyboard type of the device is: " + ret);
})
```
## DeviceListener
## DeviceListener<sup>9+</sup>
输入设备的描述信息。
......@@ -466,36 +275,36 @@ export default {
**系统能力:** 以下各项对应的系统能力均为SystemCapability.MultimodalInput.Input.InputDevice
| 名称 | 参数类型 | 说明 |
| ---------- | -------------------------------------- | ------------------------------------------------------------ |
| id | number | 输入设备的唯一标识,同一个物理设备反复插拔,其设备id会发生变化。 |
| name | string | 输入设备的名字。 |
| sources | Array&lt;[SourceType](#sourcetype)&gt; | 输入设备支持的源类型。比如有的键盘上附带触摸板,则此设备有keyboard和touchpad两种输入源。 |
| axisRanges | Array&lt;[axisRanges](#axisrange)&gt; | 输入设备的轴信息。 |
| bus | number | 输入设备的总线类型。 |
| product | number | 输入设备的产品信息。 |
| vendor | number | 输入设备的厂商信息。 |
| version | number | 输入设备的版本信息。 |
| phys | string | 输入设备的物理地址。 |
| uniq | string | 输入设备的唯一标识。 |
## AxisType
| 名称 | 参数类型 | 说明 |
| -------------------- | -------------------------------------- | ------------------------------------------------------------ |
| id | number | 输入设备的唯一标识,同一个物理设备反复插拔,其设备id会发生变化。 |
| name | string | 输入设备的名字。 |
| sources | Array&lt;[SourceType](#sourcetype)&gt; | 输入设备支持的源类型。比如有的键盘上附带触摸板,则此设备有keyboard和touchpad两种输入源。 |
| axisRanges | Array&lt;[axisRanges](#axisrange)&gt; | 输入设备的轴信息。 |
| bus<sup>9+</sup> | number | 输入设备的总线类型。 |
| product<sup>9+</sup> | number | 输入设备的产品信息。 |
| vendor<sup>9+</sup> | number | 输入设备的厂商信息。 |
| version<sup>9+</sup> | number | 输入设备的版本信息。 |
| phys<sup>9+</sup> | string | 输入设备的物理地址。 |
| uniq<sup>9+</sup> | string | 输入设备的唯一标识。 |
## AxisType<sup>9+</sup>
输入设备的轴类型
**系统能力:** 以下各项对应的系统能力均为SystemCapability.MultimodalInput.Input.InputDevice
| 名称 | 参数类型 | 说明 |
| ----------- | -------- | ----------------- |
| touchMajor | string | 表示touchMajor轴 |
| touchMinor | string | 表示touchMinor轴 |
| toolMinor | string | 表示toolMinor轴 |
| toolMajor | string | 表示toolMajor轴 |
| orientation | string | 表示orientation轴 |
| pressure | string | 表示pressure轴 |
| x | string | 表示x轴 |
| y | string | 表示y轴 |
| NULL | string | 无 |
| 名称 | 参数类型 | 说明 |
| ----------- | -------- | ------------------- |
| touchMajor | string | 表示touchMajor轴 |
| touchMinor | string | 表示touchMinor轴 |
| toolMinor | string | 表示toolMinor轴 |
| toolMajor | string | 表示toolMajor轴 |
| orientation | string | 表示orientation轴 |
| pressure | string | 表示pressure轴 |
| x | string | 表示x轴 |
| y | string | 表示y轴 |
| NULL | string | 无 |
## AxisRange
......@@ -503,15 +312,15 @@ export default {
**系统能力:** 以下各项对应的系统能力均为SystemCapability.MultimodalInput.Input.InputDevice
| 名称 | 参数类型 | 说明 |
| ---------- | ------------------------- | ---------------- |
| source | [SourceType](#sourcetype) | 轴的输入源类型。 |
| axis | [AxisType](axistype) | 轴的类型 |
| max | number | 轴上报的最大值 |
| min | number | 轴上报的最小值 |
| fuzz | number | |
| flat | number | |
| resolution | number | |
| 名称 | 参数类型 | 说明 |
| ----------------------- | ------------------------- | ---------------- |
| source | [SourceType](#sourcetype) | 轴的输入源类型。 |
| axis | [AxisType](axistype) | 轴的类型。 |
| max | number | 轴的最大值。 |
| min | number | 轴的最小值。 |
| fuzz<sup>9+</sup> | number | 轴的模糊值。 |
| flat<sup>9+</sup> | number | 轴的基准值。 |
| resolution<sup>9+</sup> | number | 轴的分辨率。 |
## SourceType
......@@ -539,17 +348,17 @@ export default {
| add | string | 表示输入设备插入。 |
| remove | string | 表示输入设备移除。 |
## KeyboardType
## KeyboardType<sup>9+</sup>
定义键盘输入设备的类型。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.MultimodalInput.Input.InputDevice
| 名称 | 参数类型 | 值 | 说明 |
| ------------------- | -------- | ---- | ---------------- |
| NONE | number | 0 | 表示无按键设备 |
| UNKNOWN | number | 1 | 表示未知按键设备 |
| ALPHABETIC_KEYBOARD | number | 2 | 表示全键盘设备 |
| DIGITAL_KEYBOARD | number | 3 | 表示小键盘设备 |
| HANDWRITING_PEN | number | 4 | 表示手写笔设备 |
| REMOTE_CONTROL | number | 5 | 表示遥控器设备 |
\ No newline at end of file
| 名称 | 参数类型 | 值 | 说明 |
| ------------------- | -------- | ---- | ------------------ |
| NONE | number | 0 | 表示无按键设备。 |
| UNKNOWN | number | 1 | 表示未知按键设备。 |
| ALPHABETIC_KEYBOARD | number | 2 | 表示全键盘设备。 |
| DIGITAL_KEYBOARD | number | 3 | 表示小键盘设备。 |
| HANDWRITING_PEN | number | 4 | 表示手写笔设备。 |
| REMOTE_CONTROL | number | 5 | 表示遥控器设备。 |
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册