Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
c02fa0d6
D
Docs
项目概览
OpenHarmony
/
Docs
接近 2 年 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
c02fa0d6
编写于
5月 25, 2022
作者:
H
hungry_feiwei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
inputdevice add an interface
Signed-off-by:
N
hungry_feiwei
<
huxiao31@huawei.com
>
上级
f33eb18c
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
406 addition
and
77 deletion
+406
-77
zh-cn/application-dev/reference/apis/js-apis-inputdevice.md
zh-cn/application-dev/reference/apis/js-apis-inputdevice.md
+406
-77
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-inputdevice.md
浏览文件 @
c02fa0d6
...
...
@@ -15,6 +15,65 @@
import
inputDevice
from
'
@ohos.multimodalInput.inputDevice
'
;
```
## inputDevice.on
on(type: “change”, listener: Callback
<
DeviceListener
>
): void
监听设备的热插拔事件。
**系统能力:**
SystemCapability.MultimodalInput.Input.InputDevice
**参数:**
| 参数 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------- | ---- | -------------------- |
| type | string | 是 | 输入设备的事件类型 |
| listener | Callback
<
[DeviceListener](#devicelistener)
>
| 是 | 可上报的输入设备事件 |
**示例:**
```
js
export
default
{
callback
:
function
(
type
,
deviceId
)
{
console
.
log
(
"
type:
"
+
type
+
"
, deviceId:
"
+
deviceId
)
}
testOn
:
function
()
{
inputDevice
.
on
(
"
change
"
,
this
.
callback
)
}
}
```
## inputDevice.off
on(type: “change”, listener?: Callback
<
DeviceListener
>
): void
取消监听设备的热插拔事件。
**系统能力:**
SystemCapability.MultimodalInput.Input.InputDevice
**参数:**
| 参数 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------- | ---- | -------------------- |
| type | string | 是 | 输入设备的事件类型 |
| listener | Callback
<
[DeviceListener](#devicelistener)
>
| 否 | 可上报的输入设备事件 |
**示例:**
```
js
export
default
{
callback
:
function
(
type
,
deviceId
)
{
console
.
log
(
"
type:
"
+
type
+
"
, deviceId:
"
+
deviceId
)
}
testOff
:
function
()
{
// 取消特定监听
inputDevice
.
off
(
"
change
"
,
this
.
callback
)
// 取消所有监听
inputDevice
.
off
(
"
change
"
)
}
}
```
## inputDevice.getDeviceIds
...
...
@@ -30,19 +89,27 @@ getDeviceIds(callback: AsyncCallback<Array<number>>): void
| -------- | ---------------------------------------- | ---- | ----- |
| callback | AsyncCallback
<
Array
<
number
>>
| 是 | 回调函数。 |
**示例:**
```
js
// 示例获取设备所有设备id。
inputDevice
.
getDeviceIds
(
function
(
ids
)
{
// 处理结果
});
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
function getDeviceIds(): Promise
<Array
<
number
>
>
function getDeviceIds(): Promise
<<
Array
<
number
>>
获取所有输入设备的id列表,使用Promise方式作为异步方法。
...
...
@@ -51,25 +118,25 @@ function getDeviceIds(): Promise<Array<number>>
**返回值:**
| 参数 | 说明 |
| ----------------------
| --
----------------------------- |
| Promise
<Array
<
number
>
> | Promise实例,用于异步获取结果。
|
| ----------------------
--- |
----------------------------- |
| Promise
<Array
&
lt
;
number
>
> | Promise实例,用于异步获取结果
|
**示例:**
```
js
// 示例获取设备所有设备id。
let
promise
=
inputDevice
.
getDeviceIds
();
promise
.
then
((
ids
)
=>
{
// 处理结果
}).
catch
((
err
)
=>
{
// 处理异常
});
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.getDevice
getDevice(deviceId: number, callback: AsyncCallback
<
InputDeviceData
>
): void
...
...
@@ -88,86 +155,311 @@ getDevice(deviceId: number, callback: AsyncCallback<InputDeviceData>): voi
**示例:**
```
js
// 示例获取设备id为1的设备信息。
inputDevice
.
getDevice
(
1
,
function
(
deviceData
)
{
// 处理结果
});
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
"
);
}
}
```
## inputDevice.getDevice
function getDevice(deviceId: number): Promise
<InputDeviceData>
function getDevice(deviceId: number): Promise
<
InputDeviceData
>
获取输入设备的描述信息,使用Promise方式作为异步方法。
**系统能力:**
SystemCapability.MultimodalInput.Input.InputDevice
**参数:**
| 参数 | 类型 | 必填 | 说明 |
| -------- | ------ | ---- | ---------------------- |
| deviceId | number | 是 | 需要获取信息的设备id。 |
**返回值:**
| 参数 | 说明 |
| ------------------------
| --
----------------------------- |
| Promise
<InputDeviceData>
| Promise实例,用于异步获取结果。
|
| ------------------------
-------------------------- |
----------------------------- |
| Promise
<
[InputDeviceData](#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.supportKeys
supportKeys(deviceId: number, keys: Array
<
KeyCode
>
, callback: Callback
<
Array
<
boolean
>>
): void;
## inputDevice.on<sup>9+</sup>
获取输入设备的描述信息,使用callback方式作为异步方法。
**系统能力:**
SystemCapability.MultimodalInput.Input.InputDevice
**参数:**
on(type: "change", listener: Callback
<DeviceListener>
): void
| 参数 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
| deviceId | number | 是 | 输入设备的唯一标识,同一个物理设备反复插拔,其设备id会发生变化。 |
| keys | Array
<
KeyCode
>
| 是 | 需要查询的键码值,最多支持5个按键查询。 |
| callback | Callback
<
Array
<
boolean
>>
| 是 | 回调函数,异步返回查询结果。 |
**示例:**
开始监听设备插拔事件。
```
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
);
}
}
```
## inputDevice.supportKeys
supportKeys(deviceId: number, keys: Array
<
KeyCode
>
): Promise
<
Array
<
boolean
>>
;
获取输入设备的描述信息,使用Promise方式作为异步方法。
**系统能力:**
SystemCapability.MultimodalInput.Input.InputDevice
**参数:**
| 参数 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------------------------------------------ |
| deviceId | number | 是 | 输入设备的唯一标识,同一个物理设备反复插拔,其设备id会发生变化。 |
| keys | Array
<
KeyCode
>
| 是 | 需要查询的键码值,最多支持5个按键查询。 |
**返回值:**
| 参数 | 说明 |
| ----------------------------------- | ----------------------------- |
| Promise
<
Array
<
boolean
>>
| Promise实例,用于异步获取结果 |
**示例:**
```
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
);
})
}
}
```
## inputDevice.setPointerSpeed
setPointerSpeed(speed: number, callback: AsyncCallback
<
void
>
): void;
设置光标移动的速度,使用callback方式作为异步方法。
**系统能力:**
SystemCapability.MultimodalInput.Input.InputDevice
**参数:**
| 参数 | 类型 | 必填 | 说明 |
| -------- | ------------------------
| ---- |
---------- |
|
type | string | 是 | 监听类型
。 |
|
listener | Callback
<DeviceListener>
| 是 | 回调函数。
|
| -------- | ------------------------
-------------- | ---- | ------
---------- |
|
speed | number | 是 | 光标移动的速度
。 |
|
callback | AsyncCallback
<
Array
<
void
>>
| 是 | 回调函数。
|
**示例:**
```
js
// 示例监听设备插拔事件
inputDevice
.
on
(
"
change
"
,
function
(
deviceChangedData
)
{
// 处理结果
});
export
default
{
callback
:
function
()
{
console
.
log
(
"
The callback function is called.
"
);
},
testSetPointerSpeed
:
function
()
{
inputDevice
.
setPointerSpeed
(
100
,
this
.
callback
);
}
}
```
## inputDevice.
off
## inputDevice.
setPointerSpeed
function off(type: "change", listener?: Callback
<DeviceListener>
): void;
setPointerSpeed(speed: number): Promise
<
void
>
;
停止监听设备插拔事件
。
设置光标移动的速度,使用Promise方式作为异步方法
。
**系统能力:**
SystemCapability.MultimodalInput.Input.InputDevice
**参数:**
| 参数 | 类型 | 必填 | 说明 |
| ----- | ------ | ---- | ---------------- |
| speed | number | 是 | 光标移动的速度。 |
**返回值:**
| 参数 | 说明 |
| ------------------- | ----------------------------- |
| Promise
<
void
>
| Promise实例,用于异步获取结果 |
**示例:**
```
js
export
default
{
testSetPointerSpeed
:
function
()
{
inputDevice
.
setPointerSpeed
(
100
).
then
(()
=>
{
console
.
log
(
"
The callback function is called.
"
);
})
}
}
```
## inputDevice.getPointerSpeed
getPointerSpeed(callback: AsyncCallback
<
number
>
): void;
获取光标移动的速度,使用callback方式作为异步方法。
**系统能力:**
SystemCapability.MultimodalInput.Input.InputDevice
**参数:**
| 参数 | 类型 | 必填 | 说明 |
| -------- | ------------------------ | ---- | -------------------- |
| type | string | 是 | 监听类型。 |
| listener | Callback
<DeviceListener>
| 否 | 停止监听的回调函数。 |
| -------- | --------------------------- | ---- | ---------------------------- |
| callback | AsyncCallback
<
number
>
| 是 | 回调函数,异步返回查询结果。 |
**示例:**
```
js
export
default
{
callback
:
function
(
ret
)
{
console
.
log
(
"
The cursor movement speed is:
"
+
ret
);
},
testGetPointerSpeed
:
function
()
{
inputDevice
.
getPointerSpeed
(
this
.
callback
);
}
}
```
## inputDevice.getPointerSpeed
getPointerSpeed(): Promise
<
number
>
;
获取光标移动的速度,使用Promise方式作为异步方法。
**系统能力:**
SystemCapability.MultimodalInput.Input.InputDevice
**返回值:**
| 参数 | 说明 |
| --------------------- | ----------------------------- |
| Promise
<
number
>
| Promise实例,用于异步获取结果 |
**示例:**
```
js
// 示例取消监听设备插拔事件
inputDevice
.
off
(
"
change
"
);
export
default
{
testGetPointerSpeed
:
function
()
{
inputDevice
.
getPointerSpeed
().
then
((
ret
)
=>
{
console
.
log
(
"
The cursor movement speed is:
"
+
ret
);
})
}
}
```
## inputDevice.getKeyboardType
getKeyboardType(deviceId: number, callback: AsyncCallback
<
KeyboardType
>
): void;
查询输入设备的键盘类型,使用callback方式作为异步方法。
**系统能力:**
SystemCapability.MultimodalInput.Input.InputDevice
**参数:**
| 参数 | 类型 | 必填 | 说明 |
| -------- | -------------------------------------------------- | ---- | ------------------------------------------------------------ |
| deviceId | number | 是 | 输入设备的唯一标识,同一个物理设备反复插拔,其设备id会发生变化。 |
| callback | AsyncCallback
<
[KeyboardType](#keyboardtype)
>
| 是 | 回调函数,异步返回查询结果。 |
**示例:**
```
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
);
}
}
```
## inputDevice.getKeyboardType
getKeyboardType(deviceId: number,): Promise
<
KeyboardType
>
;
查询输入设备的键盘类型,使用Promise方式作为异步方法。
**系统能力:**
SystemCapability.MultimodalInput.Input.InputDevice
**返回值:**
| 参数 | 说明 |
| -------------------------------------------- | ----------------------------- |
| Promise
<
[KeyboardType](#keyboardtype)
>
| Promise实例,用于异步获取结果 |
**示例:**
```
js
export
default
{
testGetKeyboardType
:
function
()
{
inputDevice
.
getKeyboardType
().
then
((
ret
)
=>
{
console
.
log
(
"
The keyboard type of the device is:
"
+
ret
);
})
}
}
```
## DeviceListener
输入设备的描述信息。
**系统能力:**
以下各项对应的系统能力均为SystemCapability.MultimodalInput.Input.InputDevice
| 名称 | 参数类型 | 说明 |
| -------- | --------------------------- | ------------------------------------------------------------ |
| type |
[
ChangedType
](
#changedtype
)
| 表示输入设备插入或者移除。 |
| deviceId | number | 输入设备的唯一标识,同一个物理设备反复插拔,其设备id会发生变化。 |
## InputDeviceData
输入设备的描述信息。
...
...
@@ -175,14 +467,35 @@ inputDevice.off("change");
**系统能力:**
以下各项对应的系统能力均为SystemCapability.MultimodalInput.Input.InputDevice
| 名称 | 参数类型 | 说明 |
| -------
| -------------------------------------- |
---------------------------------------- |
| -------
--- | -------------------------------------- | --------------------
---------------------------------------- |
| id | number | 输入设备的唯一标识,同一个物理设备反复插拔,其设备id会发生变化。 |
| name | string | 输入设备的名字。 |
| sources | Array
<
[SourceType](#sourcetype)
>
| 输入设备支持的源类型。比如有的键盘上附带触摸板,则此设备有keyboard和touchpad两种输入源。 |
| axisRanges | Array
<
[axisRanges](#axisrange)
>
| 输入设备的轴信息。 |
| bus | number | 输入设备的总线类型。 |
| product | number | 输入设备的产品信息。 |
| vendor | number | 输入设备的厂商信息。 |
| version | number | 输入设备的版本信息。 |
| phys | string | 输入设备的物理地址。 |
| uniq | string | 输入设备的唯一标识。 |
## AxisType
轴类型,本接口在OpenHarmony 3.1 Release版本仅为接口定义,暂不支持使用。接口将在OpenHarmony 3.1 MR版本中提供使用支持。
输入设备的轴类型
**系统能力:**
以下各项对应的系统能力均为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 | 无 |
## AxisRange
...
...
@@ -191,13 +504,14 @@ inputDevice.off("change");
**系统能力:**
以下各项对应的系统能力均为SystemCapability.MultimodalInput.Input.InputDevice
| 名称 | 参数类型 | 说明 |
| ------ | ------------------------- | ---------------- |
| ------
----
| ------------------------- | ---------------- |
| source |
[
SourceType
](
#sourcetype
)
| 轴的输入源类型。 |
| axis |
[
AxisType
](
axistype
)
| 轴的类型。 |
| max | number | 轴上报的最大值。 |
| min | number | 轴上报的最小值。 |
| axis |
[
AxisType
](
axistype
)
| 轴的类型 |
| max | number | 轴上报的最大值 |
| min | number | 轴上报的最小值 |
| fuzz | number | |
| flat | number | |
| resolution | number | |
## SourceType
...
...
@@ -214,13 +528,28 @@ inputDevice.off("change");
| touchpad | string | 表示输入设备是触摸板。 |
| joystick | string | 表示输入设备是操纵杆。 |
##
DeviceListener
##
ChangeType
设备
插拔事件。
定义监听设备热
插拔事件。
**系统能力:**
以下各项对应的系统能力均为SystemCapability.MultimodalInput.Input.InputDevice
| 名称 | 参数类型 | 说明 |
| -------- | -------- | ----------------------------------- |
| type | string | 表示设备插拔类型,取值add和remove。 |
| deviceId | number | 表示设备id。 |
\ No newline at end of file
| ------ | -------- | ------------------ |
| add | string | 表示输入设备插入。 |
| remove | string | 表示输入设备移除。 |
## KeyboardType
定义键盘输入设备的类型。
**系统能力:**
以下各项对应的系统能力均为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
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录