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

!4084 InputDevice和inputmonitor补充新增接口说明

Merge pull request !4084 from mayunteng/tmp
......@@ -11,7 +11,7 @@
## 导入模块
```
```js
import inputDevice from '@ohos.multimodalInput.inputDevice';
```
......@@ -33,20 +33,11 @@ getDeviceIds(callback: AsyncCallback<Array<number>>): void
**示例:**
```
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");
}
}
```js
// 示例获取设备所有设备id。
inputDevice.getDeviceIds(function (ids) {
// 处理结果
});
```
## inputDevice.getDeviceIds
......@@ -59,24 +50,20 @@ function getDeviceIds(): Promise<Array<number>>
**返回值:**
| 参数 | 说明 |
| ---------------------- | ------------------ |
| Promise<Array<number>> | Promise实例,用于异步获取结果 |
| 参数 | 说明 |
| ---------------------- | ------------------------------- |
| Promise<Array<number>> | Promise实例,用于异步获取结果 |
**示例:**
```
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));
});
}
}
```js
// 示例获取设备所有设备id。
let promise = inputDevice.getDeviceIds();
promise.then((ids)=> {
// 处理结果
}).catch((err)=>{
// 处理异常
});
```
......@@ -100,24 +87,11 @@ getDevice(deviceId: number, callback: AsyncCallback&lt;InputDeviceData&gt;): voi
**示例:**
```
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");
}
}
```js
// 示例获取设备id为1的设备信息。
inputDevice.getDevice(1, function (deviceData) {
// 处理结果
});
```
## inputDevice.getDevice
......@@ -130,34 +104,69 @@ function getDevice(deviceId: number): Promise<InputDeviceData>
**返回值:**
| 参数 | 说明 |
| ------------------------ | ------------------ |
| Promise<InputDeviceData> | Promise实例,用于异步获取结果 |
| 参数 | 说明 |
| ------------------------ | ------------------------------- |
| Promise<InputDeviceData> | Promise实例,用于异步获取结果 |
**示例:**
```js
// 示例获取设备id为1的设备信息。
let promise = inputDevice.getDevice(1);
promise.then((data) => {
// 处理结果
}).catch((err) => {
// 处理异常
});
```
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));
});
}
}
## inputDevice.on<sup>9+</sup>
on(type: "change", listener: Callback<DeviceListener>): void
开始监听设备插拔事件。
**系统能力:** SystemCapability.MultimodalInput.Input.InputDevice
**返回值:**
| 参数 | 类型 | 必填 | 说明 |
| -------- | ------------------------ | ---- | ---------- |
| type | string | 是 | 监听类型。 |
| listener | Callback<DeviceListener> | 是 | 回调函数。 |
**示例:**
```js
// 示例监听设备插拔事件
inputDevice.on("change", function (deviceChangedData) {
// 处理结果
});
```
## inputDevice.off
function off(type: "change", listener?: Callback<DeviceListener>): void;
停止监听设备插拔事件。
**系统能力:** SystemCapability.MultimodalInput.Input.InputDevice
**返回值:**
| 参数 | 类型 | 必填 | 说明 |
| -------- | ------------------------ | ---- | -------------------- |
| type | string | 是 | 监听类型。 |
| listener | Callback<DeviceListener> | 否 | 停止监听的回调函数。 |
**示例:**
```js
// 示例取消监听设备插拔事件
inputDevice.off("change");
```
## InputDeviceData
......@@ -181,12 +190,12 @@ export default {
**系统能力:** 以下各项对应的系统能力均为SystemCapability.MultimodalInput.Input.InputDevice
| 名称 | 参数类型 | 说明 |
| ------ | ------------------------- | -------- |
| 名称 | 参数类型 | 说明 |
| ------ | ------------------------- | ---------------- |
| source | [SourceType](#sourcetype) | 轴的输入源类型。 |
| axis | [AxisType](axistype) | 轴的类型 |
| max | number | 轴上报的最大值 |
| min | number | 轴上报的最小值 |
| axis | [AxisType](axistype) | 轴的类型 |
| max | number | 轴上报的最大值 |
| min | number | 轴上报的最小值 |
......@@ -204,3 +213,14 @@ export default {
| trackball | string | 表示输入设备是轨迹球。 |
| touchpad | string | 表示输入设备是触摸板。 |
| joystick | string | 表示输入设备是操纵杆。 |
## DeviceListener
设备插拔事件。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.MultimodalInput.Input.InputDevice
| 名称 | 参数类型 | 说明 |
| -------- | -------- | ----------------------------------- |
| type | string | 表示设备插拔类型,取值add和remove。 |
| deviceId | number | 表示设备id。 |
\ No newline at end of file
......@@ -10,7 +10,7 @@
## 导入模块
```
```js
import inputMonitor from '@ohos.multimodalInput.inputMonitor';
```
......@@ -24,84 +24,97 @@ ohos.permission.INPUT_MONITORING
on(type: "touch", receiver: TouchEventReceiver): void
开始监听全局输入
开始监听全局触屏事件
**需要权限:**ohos.permission.INPUT_MONITORING
**系统能力:**SystemCapability.MultimodalInput.Input.InputMonitor
**参数:**
| 参数 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | -------------------- |
| type | string | 是 | 监听输入事件类型,只支持“touch”。 |
| receiver | [TouchEventReceiver](#toucheventreceiver) | 是 | 触摸输入事件回调函数。 |
| 参数 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------- | ---- | ------------------------------- |
| type | string | 是 | 监听输入事件类型,取值“touch”。 |
| receiver | [TouchEventReceiver](#toucheventreceiver) | 是 | 触摸输入事件回调函数。 |
**示例:**
```js
inputMonitor.off("touch", (event) => {
// 消费触屏事件
return false;
});
```
export default {
callback: function (value) {
if (checkEvent(value)) {
//事件满足业务要求,事件被消费
return true;
} else {
//事件不满足业务要求,事件未被消费
return false;
}
},
testOn: function () {
console.info("InputMonitorJsTest---start---testOn");
inputMonitor.on(
"touch",
this.callback
);
console.info("InputMonitorJsTest---end---testOn");
}
}
on(type: "mouse", receiver: TouchEventReceiver): void
开始监听全局鼠标事件。
**需要权限:** ohos.permission.INPUT_MONITORING
**系统能力:** SystemCapability.MultimodalInput.Input.InputMonitor
**参数:**
| 参数 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------------- |
| type | string | 是 | 监听输入事件类型,取值“mouse”。 |
| receiver | Callback<MouseEvent> | 是 | 鼠标输入事件回调函数。 |
**示例:**
```js
inputMonitor.off("mouse", (event) => {
// 消费鼠标事件
});
```
## inputMonitor.off
off(type: "touch", receiver: TouchEventReceiver): void
停止监听全局输入
开始监听全局触屏事件
**需要权限:**ohos.permission.INPUT_MONITORING
**系统能力:**SystemCapability.MultimodalInput.Input.InputMonitor
**参数:**
| 参数 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | -------------------- |
| type | string | 是 | 监听输入事件类型,只支持“touch”。 |
| receiver | [TouchEventReceiver](#toucheventreceiver) | 否 | 触摸输入事件回调函数。 |
| 参数 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------- | ---- | ------------------------------- |
| type | string | 是 | 监听输入事件类型,取值“touch”。 |
| receiver | [TouchEventReceiver](#toucheventreceiver) | 否 | 触摸输入事件回调函数。 |
**示例:**
```js
inputMonitor.off("touch");
```
export default {
callback: function (value) {
if (checkEvent(value)) {
//事件满足业务要求,事件被消费
return true;
} else {
//事件不满足业务要求,事件未被消费
return false;
}
},
testOff: function () {
console.info("InputMonitorJsTest---start---testOff");
inputMonitor.off(
"touch",
this.callback
);
console.info("InputMonitorJsTest---end---testOff");
}
}
off(type: "mouse", receiver?: Callback<MouseEvent>): void
停止监听全局鼠标事件。
**需要权限:**ohos.permission.INPUT_MONITORING
**系统能力:**SystemCapability.MultimodalInput.Input.InputMonitor
**参数:**
| 参数 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------------- |
| type | string | 是 | 监听输入事件类型,取值“mouse”。 |
| receiver | Callback<MouseEvent> | 否 | 鼠标输入事件回调函数。 |
**示例:**
```js
inputMonitor.off("mouse");
```
## TouchEventReceiver
触摸输入事件的回调函数,如果返回true,则触摸输入将被监听器消耗(系统执行关闭动作)。
......@@ -125,24 +138,10 @@ export default {
**示例:**
```
export default {
callback: function (value) { //此处为(touchEvent:TouchEvent): Boolean 方法的实现
if (checkEvent(value)) {
//事件满足业务要求,事件被消费
return true;
} else {
//事件不满足业务要求,事件未被消费
return false;
}
},
testOff: function () {
console.info("InputMonitorJsTest---start---testOff");
inputMonitor.off(
"touch",
this.callback
);
console.info("InputMonitorJsTest---end---testOff");
}
}
```js
inputMonitor.on("touch", (event) => {
// 消费触屏事件
return false;
});
inputMonitor.off("touch");
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册