Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
accbd6fb
D
Docs
项目概览
OpenHarmony
/
Docs
1 年多 前同步成功
通知
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看板
提交
accbd6fb
编写于
5月 26, 2022
作者:
H
hungry_feiwei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
inputdevice add an interface
Signed-off-by:
N
hungry_feiwei
<
huxiao31@huawei.com
>
上级
0ef49cc1
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
84 addition
and
275 deletion
+84
-275
zh-cn/application-dev/reference/apis/js-apis-inputdevice.md
zh-cn/application-dev/reference/apis/js-apis-inputdevice.md
+84
-275
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-inputdevice.md
浏览文件 @
accbd6fb
...
...
@@ -15,7 +15,7 @@
import
inputDevice
from
'
@ohos.multimodalInput.inputDevice
'
;
```
## inputDevice.on
## inputDevice.on
<sup>9+</sup>
on(type: “change”, listener: Callback
<
DeviceListener
>
): void
...
...
@@ -33,17 +33,12 @@ on(type: “change”, listener: Callback<DeviceListener>): 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
<
DeviceListener
>
): void
...
...
@@ -61,18 +56,7 @@ on(type: “change”, listener?: Callback<DeviceListener>): 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<Array<number>>): 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<<Array<number>>
**示例:**
```
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<InputDeviceData>): 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<InputDeviceData>
**示例:**
```
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
<
KeyCode
>
, callback: Callback
<
Array
<
boolean
>>
): void;
...
...
@@ -236,18 +175,13 @@ supportKeys(deviceId: number, keys: Array<KeyCode>, callback: Callback<
**示例:**
```
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
<
KeyCode
>
): Promise
<
Array
<
boolean
>>
;
...
...
@@ -271,130 +205,13 @@ supportKeys(deviceId: number, keys: Array<KeyCode>): Promise<Array<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
<
void
>
): void;
设置光标移动的速度,使用callback方式作为异步方法。
**系统能力:**
SystemCapability.MultimodalInput.Input.InputDevice
**参数:**
| 参数 | 类型 | 必填 | 说明 |
| -------- | -------------------------------------- | ---- | ---------------- |
| speed | number | 是 | 光标移动的速度。 |
| callback | AsyncCallback
<
Array
<
void
>>
| 是 | 回调函数。 |
**示例:**
```
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
<
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
**参数:**
| 参数 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ---------------------------- |
| 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
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
<
KeyboardType
>
): void;
...
...
@@ -412,18 +229,13 @@ getKeyboardType(deviceId: number, callback: AsyncCallback<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
);
}
}
// 示例查询设备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
<
KeyboardType
>
;
...
...
@@ -440,16 +252,13 @@ getKeyboardType(deviceId: number,): Promise<KeyboardType>;
**示例:**
```
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
<
[SourceType](#sourcetype)
>
| 输入设备支持的源类型。比如有的键盘上附带触摸板,则此设备有keyboard和touchpad两种输入源。 |
| axisRanges | Array
<
[axisRanges](#axisrange)
>
| 输入设备的轴信息。 |
| bus
| number | 输入设备的总线类型。 |
| product
| number | 输入设备的产品信息。 |
| vendor
| number | 输入设备的厂商信息。 |
| version
| number | 输入设备的版本信息。 |
| phys
| string | 输入设备的物理地址。 |
| uniq
| string | 输入设备的唯一标识。 |
## AxisType
| 名称
| 参数类型 | 说明 |
| ----------
----------
| -------------------------------------- | ------------------------------------------------------------ |
| id
| number | 输入设备的唯一标识,同一个物理设备反复插拔,其设备id会发生变化。 |
| name
| string | 输入设备的名字。 |
| sources
| Array
<
[SourceType](#sourcetype)
>
| 输入设备支持的源类型。比如有的键盘上附带触摸板,则此设备有keyboard和touchpad两种输入源。 |
| axisRanges
| Array
<
[axisRanges](#axisrange)
>
| 输入设备的轴信息。 |
| 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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录