Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
eb74bef9
D
Docs
项目概览
OpenHarmony
/
Docs
大约 2 年 前同步成功
通知
161
Star
293
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看板
未验证
提交
eb74bef9
编写于
11月 01, 2022
作者:
O
openharmony_ci
提交者:
Gitee
11月 01, 2022
浏览文件
操作
浏览文件
下载
差异文件
!11152 inputdevice资料修改
Merge pull request !11152 from mayunteng/master
上级
cd982c66
930a3cca
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
251 addition
and
240 deletion
+251
-240
zh-cn/application-dev/reference/apis/js-apis-inputdevice.md
zh-cn/application-dev/reference/apis/js-apis-inputdevice.md
+143
-134
zh-cn/application-dev/reference/apis/js-apis-pointer.md
zh-cn/application-dev/reference/apis/js-apis-pointer.md
+108
-106
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-inputdevice.md
浏览文件 @
eb74bef9
# 输入设备
# 输入设备
输入设备管理模块,用于监听输入设备连接
、断开和变化,并查看输入设备相关信息。比如监听鼠标插拔,并获取鼠标的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
<
DeviceListener
>
): void
on(type:
"change"
, listener: Callback
<
DeviceListener
>
): void
监听输入设备的热插拔事件。
监听输入设备的热插拔事件。
...
@@ -153,7 +150,7 @@ on(type: “change”, listener: Callback<DeviceListener>): void
...
@@ -153,7 +150,7 @@ on(type: “change”, listener: Callback<DeviceListener>): void
| 参数 | 类型 | 必填 | 说明 |
| 参数 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | ----------- |
| -------- | ---------------------------------------- | ---- | ----------- |
| type | string | 是 | 输入设备的事件类型。 |
| type | string | 是 | 输入设备的事件类型。 |
| listener | Callback
<
[DeviceListener](#devicelistener9)
>
| 是 |
可上报的输入设备
事件。 |
| listener | Callback
<
[DeviceListener](#devicelistener9)
>
| 是 |
回调函数,异步上报输入设备热插拔
事件。 |
**示例**
:
**示例**
:
...
@@ -161,13 +158,13 @@ on(type: “change”, listener: Callback<DeviceListener>): void
...
@@ -161,13 +158,13 @@ on(type: “change”, listener: Callback<DeviceListener>): 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
<
DeviceListener
>
): void
off(type:
"change"
, listener?: Callback
<
DeviceListener
>
): void
取消监听输入设备的热插拔事件。
取消监听输入设备的热插拔事件。
...
@@ -192,42 +189,41 @@ off(type: “change”, listener?: Callback<DeviceListener>): void
...
@@ -192,42 +189,41 @@ off(type: “change”, listener?: Callback<DeviceListener>): void
| 参数 | 类型 | 必填 | 说明 |
| 参数 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | ----------- |
| -------- | ---------------------------------------- | ---- | ----------- |
| type | string | 是 | 输入设备的事件类型。 |
| type | string | 是 | 输入设备的事件类型。 |
| listener | Callback
<
[DeviceListener](#devicelistener9)
>
| 否 |
可上报的输入设备事件
。 |
| listener | Callback
<
[DeviceListener](#devicelistener9)
>
| 否 |
取消监听的回调函数
。 |
**示例**
:
**示例**
:
```
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
<
Array
<
number
>>
): void
getDeviceIds(callback: AsyncCallback
<
Array
<
number
>>
): void
获取所有输入设备的id列表,使用
callback方式作为异步方法
。
获取所有输入设备的id列表,使用
AsyncCallback异步方式返回结果
。
从API version 9 开始不再维护,建议使用
[
inputDevice.getDeviceList
](
#inputdevicegetdevicelist9
)
代替。
从API version 9 开始不再维护,建议使用
[
inputDevice.getDeviceList
](
#inputdevicegetdevicelist9
)
代替。
...
@@ -235,15 +231,19 @@ getDeviceIds(callback: AsyncCallback<Array<number>>): void
...
@@ -235,15 +231,19 @@ getDeviceIds(callback: AsyncCallback<Array<number>>): void
**参数**
:
**参数**
:
| 参数
| 类型 | 必填 | 说明
|
| 参数
| 类型 | 必填 | 说明
|
| -------- | ---------------------------------------- | ---- | ----- |
| -------- | ---------------------------------------- | ---- | -----
-----------------------------------
|
| callback | AsyncCallback
<
Array
<
number
>>
| 是
| 回调函数
。 |
| callback | AsyncCallback
<
Array
<
number
>>
| 是
| 回调函数,异步返回所有输入设备的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
<
Array
<
number
>>
getDeviceIds(): Promise
<
Array
<
number
>>
获取所有输入设备的id列表,使用Promise
方式作为异步方法
。
获取所有输入设备的id列表,使用Promise
异步方式返回结果
。
从API version 9 开始不再维护,建议使用
[
inputDevice.getDeviceList
](
#inputdevicegetdevicelist9
)
代替。
从API version 9 开始不再维护,建议使用
[
inputDevice.getDeviceList
](
#inputdevicegetdevicelist9
)
代替。
...
@@ -259,15 +259,15 @@ getDeviceIds(): Promise<Array<number>>
...
@@ -259,15 +259,15 @@ getDeviceIds(): Promise<Array<number>>
**返回值**
:
**返回值**
:
| 参数
| 说明
|
| 参数
| 说明
|
| ---------------------------------- | ------------------- |
| ---------------------------------- | -------------------
------------------------
|
| Promise
<
Array
<
number
>>
| Promise
实例,用于异步获取结果
。 |
| Promise
<
Array
<
number
>>
| Promise
对象,异步返回所有输入设备的id列表
。 |
**示例**
:
**示例**
:
```
js
```
js
inputDevice
.
getDevice
Ids
().
then
((
ids
)
=>
{
inputDevice
.
getDevice
List
().
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
<
InputDeviceData
>
): void
getDevice(deviceId: number, callback: AsyncCallback
<
InputDeviceData
>
): void
获取
输入设备的描述信息,使用callback方式作为异步方法
。
获取
指定输入设备的信息,使用AsyncCallback异步方式返回结果
。
从API version 9 开始不再维护,建议使用
[
inputDevice.getDeviceInfo
](
#inputdevicegetdeviceinfo9
)
代替。
从API version 9 开始不再维护,建议使用
[
inputDevice.getDeviceInfo
](
#inputdevicegetdeviceinfo9
)
代替。
...
@@ -283,17 +283,21 @@ getDevice(deviceId: number, callback: AsyncCallback<InputDeviceData>): voi
...
@@ -283,17 +283,21 @@ getDevice(deviceId: number, callback: AsyncCallback<InputDeviceData>): voi
**参数**
:
**参数**
:
| 参数
| 类型 | 必填 | 说明
|
| 参数
| 类型 | 必填 | 说明
|
| -------- | ----------------------------------------
| ---- |
--------------------------- |
| -------- | ----------------------------------------
---------------- | ---- | -----
--------------------------- |
| deviceId | number
| 是 | 需要获取信息的设备id。
|
| deviceId | number
| 是 | 输入设备id。
|
| callback | AsyncCallback
<
[InputDeviceData](#inputdevicedata)
>
| 是
| 回调函数,异步返回InputDeviceData对象
。 |
| callback | AsyncCallback
<
[InputDeviceData](#inputdevicedata)
>
| 是
| 回调函数,异步返回输入设备信息
。 |
**示例**
:
**示例**
:
```
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
<
InputDeviceData
>
getDevice(deviceId: number): Promise
<
InputDeviceData
>
获取
输入设备的描述信息,使用Promise方式作为异步方法
。
获取
指定输入设备的信息,使用Promise异步方式返回结果
。
从API version 9 开始不再维护,建议使用
[
inputDevice.getDeviceInfo
](
#inputdevicegetdeviceinfo9
)
代替。
从API version 9 开始不再维护,建议使用
[
inputDevice.getDeviceInfo
](
#inputdevicegetdeviceinfo9
)
代替。
...
@@ -309,22 +313,22 @@ getDevice(deviceId: number): Promise<InputDeviceData>
...
@@ -309,22 +313,22 @@ getDevice(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的设备
信息。
inputDevice
.
getDevice
(
1
).
then
((
inputDevice
)
=>
{
inputDevice
.
getDevice
Info
(
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
<
KeyCode
>
, callback: Callback
<
Array
<
boolean
>>
): void
supportKeys(deviceId: number, keys: Array
<
KeyCode
>
, callback: Callback
<
Array
<
boolean
>>
): void
获取输入设备
支持的键码值,使用callback方式作为异步方法
。
获取输入设备
是否支持指定的键码值,使用Callback异步方式返回结果
。
**系统能力**
:SystemCapability.MultimodalInput.Input.InputDevice
**系统能力**
:SystemCapability.MultimodalInput.Input.InputDevice
**参数**
:
**参数**
:
| 参数
| 类型 | 必填 | 说明
|
| 参数
| 类型 | 必填 | 说明
|
| -------- | ------------------------------------ | ---- | --------------------------------- |
| -------- | ------------------------------------ | ---- | ---------------------------------
---------------------
|
| deviceId | number | 是
| 输入设备的唯一标识,同一个物理设备反复插拔,其
设备id会发生变化。 |
| deviceId | number | 是
| 输入设备id,同一个物理设备反复插拔,
设备id会发生变化。 |
| keys | Array
<
KeyCode
>
| 是
| 需要查询的键码值,最多支持5个按键查询。
|
| keys | Array
<
KeyCode
>
| 是
| 需要查询的键码值,最多支持5个按键查询。
|
| callback | Callback
<
Array
<
boolean
>>
| 是
| 回调函数,异步返回查询结果。
|
| callback | Callback
<
Array
<
boolean
>>
| 是
| 回调函数,异步返回查询结果。
|
**示例**
:
**示例**
:
```
js
```
js
//
示例查询id为1的
设备对于17、22和2055按键的支持情况。
//
查询id为1的输入
设备对于17、22和2055按键的支持情况。
try
{
try
{
inputDevice
.
supportKeys
(
1
,
[
17
,
22
,
2055
],
(
error
,
re
t
)
=>
{
inputDevice
.
supportKeys
(
1
,
[
17
,
22
,
2055
],
(
error
,
supportResul
t
)
=>
{
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
<
KeyCode
>
): Promise
<
Array
<
boolean
>>
supportKeys(deviceId: number, keys: Array
<
KeyCode
>
): Promise
<
Array
<
boolean
>>
获取输入设备
支持的键码值,使用Promise方式作为异步方法
。
获取输入设备
是否支持指定的键码值,使用Promise异步方式返回结果
。
**系统能力**
:SystemCapability.MultimodalInput.Input.InputDevice
**系统能力**
:SystemCapability.MultimodalInput.Input.InputDevice
**参数**
:
**参数**
:
| 参数
| 类型 | 必填 | 说明
|
| 参数
| 类型 | 必填 | 说明
|
| -------- | -------------------- | ---- | --------------------------------- |
| -------- | -------------------- | ---- | ---------------------------------
---------------------
|
| deviceId | number | 是
| 输入设备的唯一标识,同一个物理设备反复插拔,其
设备id会发生变化。 |
| deviceId | number | 是
| 输入设备id,同一个物理设备反复插拔,
设备id会发生变化。 |
| keys | Array
<
KeyCode
>
| 是
| 需要查询的键码值,最多支持5个按键查询。
|
| keys | Array
<
KeyCode
>
| 是
| 需要查询的键码值,最多支持5个按键查询。
|
**返回值**
:
**返回值**
:
| 参数
| 说明
|
| 参数
| 说明
|
| ----------------------------------- | ------------------- |
| ----------------------------------- | -------------------
------------
|
| Promise
<
Array
<
boolean
>>
| Promise
实例,用于异步获取
结果。 |
| Promise
<
Array
<
boolean
>>
| Promise
对象,异步返回查询
结果。 |
**示例**
:
**示例**
:
```
js
```
js
//
示例查询id为1的
设备对于17、22和2055按键的支持情况。
//
查询id为1的输入
设备对于17、22和2055按键的支持情况。
try
{
try
{
inputDevice
.
supportKeys
(
1
,
[
17
,
22
,
2055
]).
then
((
re
t
)
=>
{
inputDevice
.
supportKeys
(
1
,
[
17
,
22
,
2055
]).
then
((
supportResul
t
)
=>
{
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
<
KeyboardType
>
): void
getKeyboardType(deviceId: number, callback: AsyncCallback
<
KeyboardType
>
): void
查询输入设备的键盘类型,使用callback方式作为异步方法
。
获取输入设备的键盘类型,使用AsyncCallback异步方式返回结果
。
**系统能力**
:SystemCapability.MultimodalInput.Input.InputDevice
**系统能力**
:SystemCapability.MultimodalInput.Input.InputDevice
**参数**
:
**参数**
:
| 参数
| 类型 | 必填 | 说明
|
| 参数
| 类型 | 必填 | 说明
|
| -------- | ----------------------------------------
| ---- |
--------------------------------- |
| -------- | ----------------------------------------
----------- | ---- | ---------------------------
--------------------------------- |
| deviceId | number
| 是 | 输入设备的唯一标识,同一个物理设备反复插拔,其
设备id会发生变化。 |
| deviceId | number
| 是 | 输入设备的唯一标识,同一个物理设备反复插拔,
设备id会发生变化。 |
| callback | AsyncCallback
<
[KeyboardType](#keyboardtype9)
>
| 是
| 回调函数,异步返回查询结果。
|
| callback | AsyncCallback
<
[KeyboardType](#keyboardtype9)
>
| 是
| 回调函数,异步返回查询结果。
|
**示例**
:
**示例**
:
```
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
<
KeyboardType
>
getKeyboardType(deviceId: number): Promise
<
KeyboardType
>
查询输入设备的键盘类型,使用Promise方式作为异步方法
。
获取输入设备的键盘类型,使用AsyncCallback异步方式返回结果
。
**系统能力**
:SystemCapability.MultimodalInput.Input.InputDevice
**系统能力**
:SystemCapability.MultimodalInput.Input.InputDevice
**参数**
:
| 参数 | 类型 | 必填 | 说明 |
| -------- | ------ | ---- | ------------------------------------------------------------ |
| deviceId | number | 是 | 输入设备的唯一标识,同一个物理设备反复插拔,设备id会发生变化。 |
**返回值**
:
**返回值**
:
| 参数
| 说明
|
| 参数
| 说明
|
| ----------------------------------------
|
------------------- |
| ----------------------------------------
----- | ------------
------------------- |
| Promise
<
[KeyboardType](#keyboardtype9)
>
| Promise
实例,用于异步获取
结果。 |
| Promise
<
[KeyboardType](#keyboardtype9)
>
| 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
<
[SourceType](#sourcetype)
>
| 输入设备支持的源类型。比如有的键盘上附带触摸板,则此设备有keyboard和touchpad两种输入源。 |
| sources | Array
<
[SourceType](#sourcetype)
>
| 输入设备支持的源类型。比如有的键盘上附带触摸板,则此设备有keyboard和touchpad两种输入源。 |
| axisRanges | Array
<
[axisRanges](#axisrange)
>
| 输入设备的轴信息。 |
| axisRanges | Array
<
[axisRanges](#axisrange)
>
| 输入设备的轴信息。
|
| 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
...
...
zh-cn/application-dev/reference/apis/js-apis-pointer.md
浏览文件 @
eb74bef9
# 鼠标指针
# 鼠标指针
鼠标指针管理模块,用于
提供鼠标指针相关属性接口
。
鼠标指针管理模块,用于
查询和设置鼠标指针相关属性
。
> **说明**:
> **说明**:
>
>
...
@@ -12,11 +12,11 @@
...
@@ -12,11 +12,11 @@
import
pointer
from
'
@ohos.multimodalInput.pointer
'
;
import
pointer
from
'
@ohos.multimodalInput.pointer
'
;
```
```
## pointer.setPointerVisib
e
le<sup>9+</sup>
## pointer.setPointerVisible<sup>9+</sup>
setPointerVisible(visible: boolean, callback: AsyncCallback
<
void
>
): void
setPointerVisible(visible: boolean, callback: AsyncCallback
<
void
>
): void
设置鼠标指针显示或者隐藏,使用
callback异步回调
。
设置鼠标指针显示或者隐藏,使用
AsyncCallback异步方式返回结果
。
**系统能力**
:SystemCapability.MultimodalInput.Input.Pointer
**系统能力**
:SystemCapability.MultimodalInput.Input.Pointer
...
@@ -24,18 +24,22 @@ setPointerVisible(visible: boolean, callback: AsyncCallback<void>): void
...
@@ -24,18 +24,22 @@ setPointerVisible(visible: boolean, callback: AsyncCallback<void>): void
| 参数 | 类型 | 必填 | 说明 |
| 参数 | 类型 | 必填 | 说明 |
| -------- | ------------------------- | ---- | ---------------------------------------- |
| -------- | ------------------------- | ---- | ---------------------------------------- |
| visible | boolean | 是 | 鼠标指针
显示或者隐藏状态,true: 鼠标指针显示; false: 鼠标指针隐藏
。 |
| visible | boolean | 是 | 鼠标指针
是否显示
。 |
| callback | AsyncCallback
<
void
>
| 是 | 回调函数。
当设置鼠标显示或隐藏成功,err为undefined,否则为错误对象。
|
| callback | AsyncCallback
<
void
>
| 是 | 回调函数。 |
**示例**
:
**示例**
:
```
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
(
err
or
)
{
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
<
void
>
setPointerVisible(visible: boolean): Promise
<
void
>
设置鼠标指针显示或者隐藏,使用Promise
方式作为异步方法
。
设置鼠标指针显示或者隐藏,使用Promise
异步方式返回结果
。
**系统能力**
:SystemCapability.MultimodalInput.Input.Pointer
**系统能力**
:SystemCapability.MultimodalInput.Input.Pointer
...
@@ -51,23 +55,23 @@ setPointerVisible(visible: boolean): Promise<void>
...
@@ -51,23 +55,23 @@ setPointerVisible(visible: boolean): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
| 参数 | 类型 | 必填 | 说明 |
| ------- | ------- | ---- | ---------------------------------------- |
| ------- | ------- | ---- | ---------------------------------------- |
| visible | boolean | 是 | 鼠标指针
显示或者隐藏状态,true: 鼠标指针显示; false: 鼠标指针隐藏
。 |
| visible | boolean | 是 | 鼠标指针
是否显示
。 |
**返回值**
:
**返回值**
:
| 参数 | 说明 |
| 参数 | 说明 |
| ------------------- | ------------------- |
| ------------------- | ------------------- |
| Promise
<
void
>
| Promise
实例,用于异步获取结果
。 |
| Promise
<
void
>
| 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
<
boolean
>
): void
isPointerVisible(callback: AsyncCallback
<
boolean
>
): void
获取鼠标指针显示或隐藏状态,使用
callback异步回调
。
获取鼠标指针显示或隐藏状态,使用
AsyncCallback异步方式返回结果
。
**系统能力**
:SystemCapability.MultimodalInput.Input.Pointer
**系统能力**
:SystemCapability.MultimodalInput.Input.Pointer
...
@@ -83,17 +87,21 @@ isPointerVisible(callback: AsyncCallback<boolean>): void
...
@@ -83,17 +87,21 @@ isPointerVisible(callback: AsyncCallback<boolean>): void
| 参数 | 类型 | 必填 | 说明 |
| 参数 | 类型 | 必填 | 说明 |
| -------- | ---------------------------- | ---- | -------------- |
| -------- | ---------------------------- | ---- | -------------- |
| callback | AsyncCallback
<
boolean
>
| 是 | 回调函数,异步返回
查询结果
。 |
| callback | AsyncCallback
<
boolean
>
| 是 | 回调函数,异步返回
鼠标指针显示或隐藏状态
。 |
**示例**
:
**示例**
:
```
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
(
err
or
)
{
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
<
boolean
>
isPointerVisible(): Promise
<
boolean
>
获取鼠标指针显示或隐藏状态,使用Promise
方式作为异步方法
。
获取鼠标指针显示或隐藏状态,使用Promise
异步方式返回结果
。
**系统能力**
:SystemCapability.MultimodalInput.Input.Pointer
**系统能力**
:SystemCapability.MultimodalInput.Input.Pointer
...
@@ -109,25 +117,21 @@ isPointerVisible(): Promise<boolean>
...
@@ -109,25 +117,21 @@ isPointerVisible(): Promise<boolean>
| 参数 | 说明 |
| 参数 | 说明 |
| ---------------------- | ------------------- |
| ---------------------- | ------------------- |
| Promise
<
boolean
>
| Promise
实例,用于异步获取结果
。 |
| Promise
<
boolean
>
| 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
<
void
>
): void
setPointerSpeed(speed: number, callback: AsyncCallback
<
void
>
): void
设置鼠标移动速度,使用
callback异步回调
。
设置鼠标移动速度,使用
AsyncCallback异步方式返回结果
。
**系统能力**
:SystemCapability.MultimodalInput.Input.Pointer
**系统能力**
:SystemCapability.MultimodalInput.Input.Pointer
...
@@ -135,18 +139,22 @@ setPointerSpeed(speed: number, callback: AsyncCallback<void>): void
...
@@ -135,18 +139,22 @@ setPointerSpeed(speed: number, callback: AsyncCallback<void>): void
| 参数 | 类型 | 必填 | 说明 |
| 参数 | 类型 | 必填 | 说明 |
| -------- | ------------------------- | ---- | ------------------------------------- |
| -------- | ------------------------- | ---- | ------------------------------------- |
| speed | number | 是 | 鼠标移动速度
设置挡位值1-11,最大值:11,最小值:1,标准值:
5。 |
| speed | number | 是 | 鼠标移动速度
,范围1-11,默认为
5。 |
| callback | AysncCallback
<
void
>
| 是 | 回调函数。
当设置鼠标速度成功,err为undefined,否则为错误对象。
|
| callback | AysncCallback
<
void
>
| 是 | 回调函数。 |
**示例**
:
**示例**
:
```
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
<
void
>
setPointerSpeed(speed: number): Promise
<
void
>
设置鼠标移动速度,使用Promise异步
回调
。
设置鼠标移动速度,使用Promise异步
方式返回结果
。
**系统能力**
:SystemCapability.MultimodalInput.Input.Pointer
**系统能力**
:SystemCapability.MultimodalInput.Input.Pointer
...
@@ -162,23 +170,23 @@ setPointerSpeed(speed: number): Promise<void>
...
@@ -162,23 +170,23 @@ setPointerSpeed(speed: number): Promise<void>
| 参数 | 类型 | 必填 | 说明 |
| 参数 | 类型 | 必填 | 说明 |
| ----- | ------ | ---- | ----------------------------------- |
| ----- | ------ | ---- | ----------------------------------- |
| speed | number | 是 | 鼠标移动速度
设置挡位值1-11,最大值:11,最小值:1,标准值:
5。 |
| speed | number | 是 | 鼠标移动速度
,范围1-11,默认为
5。 |
**返回值**
:
**返回值**
:
| 参数 | 说明 |
| 参数 | 说明 |
| ------------------- | ---------------- |
| ------------------- | ---------------- |
| Promise
<
void
>
|
无返回结果的
Promise对象。 |
| Promise
<
void
>
| 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
(
err
or
)
{
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
<
number
>
): void
getPointerSpeed(callback: AsyncCallback
<
number
>
): void
获取
当前鼠标移动速度,使用callback异步回调
。
获取
鼠标移动速度,使用AsyncCallback异步方式返回结果
。
**系统能力**
:SystemCapability.MultimodalInput.Input.Pointer
**系统能力**
:SystemCapability.MultimodalInput.Input.Pointer
...
@@ -194,17 +202,21 @@ getPointerSpeed(callback: AsyncCallback<number>): void
...
@@ -194,17 +202,21 @@ getPointerSpeed(callback: AsyncCallback<number>): void
| 参数 | 类型 | 必填 | 说明 |
| 参数 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | -------------- |
| -------- | --------------------------- | ---- | -------------- |
| callback | AsyncCallback
<
number
>
| 是 | 回调函数,异步返回
查询结果
。 |
| callback | AsyncCallback
<
number
>
| 是 | 回调函数,异步返回
鼠标移动速度
。 |
**示例**
:
**示例**
:
```
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
<
number
>
getPointerSpeed(): Promise
<
number
>
获取当前鼠标移动速度,使用Promise异步
回调
。
获取当前鼠标移动速度,使用Promise异步
方式返回结果
。
**系统能力**
:SystemCapability.MultimodalInput.Input.Pointer
**系统能力**
:SystemCapability.MultimodalInput.Input.Pointer
...
@@ -220,17 +232,17 @@ getPointerSpeed(): Promise<number>
...
@@ -220,17 +232,17 @@ getPointerSpeed(): Promise<number>
| 参数 | 说明 |
| 参数 | 说明 |
| --------------------- | ------------------- |
| --------------------- | ------------------- |
| Promise
<
number
>
| Promise实例,
用于异步获取结果
。 |
| Promise
<
number
>
| 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
(
err
or
)
{
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
<
PointerStyle
>
): void
getPointerStyle(windowId: number, callback: AsyncCallback
<
PointerStyle
>
): void
获取鼠标样式类型,使用
callback异步回调
。
获取鼠标样式类型,使用
AsyncCallback异步方式返回结果
。
**系统能力**
:SystemCapability.MultimodalInput.Input.Pointer
**系统能力**
:SystemCapability.MultimodalInput.Input.Pointer
...
@@ -246,29 +258,27 @@ getPointerStyle(windowId: number, callback: AsyncCallback<PointerStyle>):
...
@@ -246,29 +258,27 @@ getPointerStyle(windowId: number, callback: AsyncCallback<PointerStyle>):
| 参数 | 类型 | 必填 | 说明 |
| 参数 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | -------------- |
| -------- | ---------------------------------------- | ---- | -------------- |
| windowId | number | 是 |
输入设备的窗口id。
|
| windowId | number | 是 |
窗口id。
|
| callback | AsyncCallback
<
[PointerStyle](#pointerstyle9)
>
| 是 | 回调函数,异步返回
查询结果
。 |
| callback | AsyncCallback
<
[PointerStyle](#pointerstyle9)
>
| 是 | 回调函数,异步返回
鼠标样式类型
。 |
**示例**
:
**示例**
:
```
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
,
(
err
or
,
style
)
=>
{
console
.
log
(
`
The mouse pointer style is: `
+
ret
);
console
.
log
(
`
Get pointer style success, style:
${
JSON
.
stringify
(
style
)}
`
);
});
});
}
catch
(
err
)
{
}
catch
(
err
or
)
{
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
<
PointerStyle
>
getPointerStyle(windowId: number): Promise
<
PointerStyle
>
获取鼠标样式类型,使用Promise
方式作为异步方法
。
获取鼠标样式类型,使用Promise
异步方式返回结果
。
**系统能力**
:SystemCapability.MultimodalInput.Input.Pointer
**系统能力**
:SystemCapability.MultimodalInput.Input.Pointer
...
@@ -286,28 +296,26 @@ getPointerStyle(windowId: number): Promise<PointerStyle>
...
@@ -286,28 +296,26 @@ getPointerStyle(windowId: number): Promise<PointerStyle>
| 参数 | 说明 |
| 参数 | 说明 |
| ---------------------------------------- | ------------------- |
| ---------------------------------------- | ------------------- |
| Promise
<
[PointerStyle](#pointerstyle9)
>
| Promise实例,
用于异步获取结果
。 |
| Promise
<
[PointerStyle](#pointerstyle9)
>
| 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
(
err
or
)
{
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
<
void
>
): void
setPointerStyle(windowId: number, pointerStyle: PointerStyle, callback: AsyncCallback
<
void
>
): 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
<
void
>
| 是 | 回调函数。
当设置样式成功,err为undefined,否则为错误对象。
|
| callback | AysncCallback
<
void
>
| 是 | 回调函数。 |
**示例**
:
**示例**
:
```
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
(
`S
uccessfully set mouse pointer style
`
);
console
.
log
(
`S
et pointer style success
`
);
});
});
}
catch
(
err
)
{
}
catch
(
err
or
)
{
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
<
void
>
setPointerStyle(windowId: number, pointerStyle: PointerStyle): Promise
<
void
>
设置鼠标
的样式类型,使用Promise方式作为异步方法
。
设置鼠标
样式类型,使用Promise异步方式返回结果
。
**系统能力**
:SystemCapability.MultimodalInput.Input.Pointer
**系统能力**
:SystemCapability.MultimodalInput.Input.Pointer
...
@@ -365,37 +371,35 @@ setPointerStyle(windowId: number, pointerStyle: PointerStyle): Promise<void&g
...
@@ -365,37 +371,35 @@ setPointerStyle(windowId: number, pointerStyle: PointerStyle): Promise<void&g
| 参数 | 类型 | 必填 | 说明 |
| 参数 | 类型 | 必填 | 说明 |
| ------------------- | ------------------------------ | ---- | ---------------- |
| ------------------- | ------------------------------ | ---- | ---------------- |
| windowId | number | 是 |
输入设备的
窗口id。 |
| windowId | number | 是 | 窗口id。 |
| pointerStyle |
[
PointerStyle
](
#pointerstyle9
)
| 是 | 鼠标样式id。 |
| pointerStyle |
[
PointerStyle
](
#pointerstyle9
)
| 是 | 鼠标样式id。 |
| Promise
<
void
>
| void | 是 |
无返回结果的
Promise对象。 |
| Promise
<
void
>
| 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
(
`S
uccessfully set mouse pointer style
`
);
console
.
log
(
`S
et pointer style success
`
);
});
});
}
catch
(
err
)
{
}
catch
(
err
or
)
{
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录