0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
会员中心
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

鸿蒙开发设备管理:ohos.multimodalInput.inputDevice 输入设备

jf_46214456 来源:jf_46214456 作者:jf_46214456 2024-07-01 09:19 次阅读
加入交流群
微信小助手二维码

扫码添加小助手

加入工程师交流群

输入设备

输入设备管理模块,用于监听输入设备连接、断开和变化,并查看输入设备相关信息。比如监听鼠标插拔,并获取鼠标的id、name和指针移动速度等信息。

说明开发前请熟悉鸿蒙开发指导文档 :[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md]
本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

导入模块

import inputDevice from '@ohos.multimodalInput.inputDevice';

inputDevice.on9+

on(type: “change”, listener: Callback): void

监听输入设备的热插拔事件。

系统能力 :SystemCapability.MultimodalInput.Input.InputDevice

参数

参数类型必填说明
typestring输入设备的事件类型。
listenerCallback<[DeviceListener]>可上报的输入设备事件。

示例

let isPhysicalKeyboardExist = true;
inputDevice.on("change", (data) = > {
    console.log("type: " + data.type + ", deviceId: " + data.deviceId);
    inputDevice.getKeyboardType(data.deviceId, (err, ret) = > {
        console.log("The keyboard type of the device is: " + ret);
        if (ret == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'add') {
            // 监听物理键盘已连接。
            isPhysicalKeyboardExist = true;
        } else if (ret == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'remove') {
            // 监听物理键盘已断开。
            isPhysicalKeyboardExist = false;
        }
    });
});
// 根据isPhysicalKeyboardExist的值决定软键盘是否弹出。

inputDevice.off9+

off(type: “change”, listener?: Callback): void

取消监听输入设备的热插拔事件。

系统能力 :SystemCapability.MultimodalInput.Input.InputDevice

参数

参数类型必填说明
typestring输入设备的事件类型。
listenerCallback<[DeviceListener]>可上报的输入设备事件。

示例

function listener(data) {
    console.log("type: " + data.type + ", deviceId: " + data.deviceId);
}

// 单独取消listener的监听。
inputDevice.off("change", listener);

// 取消所有监听。
inputDevice.off("change");
// 取消监听后,软键盘默认都弹出。

inputDevice.getDeviceIds

getDeviceIds(callback: AsyncCallback>): void

获取所有输入设备的id列表,使用callback方式作为异步方法。

系统能力 :SystemCapability.MultimodalInput.Input.InputDevice

参数

参数类型必填说明
callbackAsyncCallback>回调函数。

示例

inputDevice.getDeviceIds((ids)= >{
    console.log("The device ID list is: " + ids);
});

inputDevice.getDeviceIds

getDeviceIds(): Promise>

获取所有输入设备的id列表,使用Promise方式作为异步方法。

系统能力 :SystemCapability.MultimodalInput.Input.InputDevice

返回值

参数说明
Promise>Promise实例,用于异步获取结果。

示例

inputDevice.getDeviceIds().then((ids)= >{
    console.log("The device ID list is: " + ids);
});

inputDevice.getDevice

getDevice(deviceId: number, callback: AsyncCallback): void

获取输入设备的描述信息,使用callback方式作为异步方法。

系统能力 :SystemCapability.MultimodalInput.Input.InputDevice

参数

参数类型必填说明
deviceIdnumber需要获取信息的设备id。
callbackAsyncCallback<[InputDeviceData]>回调函数,异步返回InputDeviceData对象。

示例

// 示例获取设备id为1的设备name信息。
inputDevice.getDevice(1, (inputDevice)= >{
    console.log("The device name is: " + inputDevice.name);
});

inputDevice.getDevice

getDevice(deviceId: number): Promise

获取输入设备的描述信息,使用Promise方式作为异步方法。

系统能力 :SystemCapability.MultimodalInput.Input.InputDevice

参数

参数类型必填说明
deviceIdnumber需要获取信息的设备id。

返回值

参数说明
Promise<[InputDeviceData]>Promise实例,用于异步获取结果。

示例

// 示例获取设备id为1的设备name信息。
inputDevice.getDevice(1).then((inputDevice)= >{
    console.log("The device name is: " + inputDevice.name);
});

inputDevice.supportKeys9+

supportKeys(deviceId: number, keys: Array, callback: Callback>): void

获取输入设备支持的键码值,使用callback方式作为异步方法。

系统能力 :SystemCapability.MultimodalInput.Input.InputDevice

参数

参数类型必填说明
deviceIdnumber输入设备的唯一标识,同一个物理设备反复插拔,其设备id会发生变化。
keysArray需要查询的键码值,最多支持5个按键查询。
callbackCallback>回调函数,异步返回查询结果。

示例

// 示例查询id为1的设备对于17、22和2055按键的支持情况。
inputDevice.supportKeys(1, [17, 22, 2055], (ret)= >{
    console.log("The query result is as follows: " + ret);
});

inputDevice.supportKeys9+

supportKeys(deviceId: number, keys: Array): Promise>

获取输入设备支持的键码值,使用Promise方式作为异步方法。

系统能力 :SystemCapability.MultimodalInput.Input.InputDevice

参数

参数类型必填说明
deviceIdnumber输入设备的唯一标识,同一个物理设备反复插拔,其设备id会发生变化。
keysArray需要查询的键码值,最多支持5个按键查询。

返回值

参数说明
Promise>Promise实例,用于异步获取结果。

示例

// 示例查询id为1的设备对于17、22和2055按键的支持情况。
inputDevice.supportKeys(1, [17, 22, 2055]).then((ret)= >{
    console.log("The query result is as follows: " + ret);
})

inputDevice.getKeyboardType9+

getKeyboardType(deviceId: number, callback: AsyncCallback): void

查询输入设备的键盘类型,使用callback方式作为异步方法。

系统能力 :SystemCapability.MultimodalInput.Input.InputDevice

参数

参数类型必填说明
deviceIdnumber输入设备的唯一标识,同一个物理设备反复插拔,其设备id会发生变化。
callbackAsyncCallback<[KeyboardType]>回调函数,异步返回查询结果。

示例

// 示例查询设备id为1的设备键盘类型。
inputDevice.getKeyboardType(1, (ret)= >{
    console.log("The keyboard type of the device is: " + ret);
});

inputDevice.getKeyboardType9+

getKeyboardType(deviceId: number): Promise

查询输入设备的键盘类型,使用Promise方式作为异步方法。

系统能力 :SystemCapability.MultimodalInput.Input.InputDevice

返回值

参数说明
Promise<[KeyboardType]>Promise实例,用于异步获取结果。

示例

// 示例查询设备id为1的设备键盘类型。
inputDevice.getKeyboardType(1).then((ret)= >{
    console.log("The keyboard type of the device is: " + ret);
})

DeviceListener9+

输入设备的描述信息。

系统能力 :以下各项对应的系统能力均为SystemCapability.MultimodalInput.Input.InputDevice

名称参数类型说明
type[ChangedType]表示输入设备插入或者移除。
deviceIdnumber输入设备的唯一标识,同一个物理设备反复插拔,其设备id会发生变化。

InputDeviceData

输入设备的描述信息。

系统能力 :以下各项对应的系统能力均为SystemCapability.MultimodalInput.Input.InputDevice

名称参数类型说明
idnumber输入设备的唯一标识,同一个物理设备反复插拔,其设备id会发生变化。
namestring输入设备的名字。
sourcesArray<[SourceType]>输入设备支持的源类型。比如有的键盘上附带触摸板,则此设备有keyboard和touchpad两种输入源。
axisRangesArray<[AxisRanges]>输入设备的轴信息。
bus9+number输入设备的总线类型。
product9+number输入设备的产品信息。
vendor9+number输入设备的厂商信息。
version9+number输入设备的版本信息。
phys9+string输入设备的物理地址。
uniq9+string输入设备的唯一标识。

AxisType9+

输入设备的轴类型。

系统能力 :以下各项对应的系统能力均为SystemCapability.MultimodalInput.Input.InputDevice

名称参数类型说明
touchMajorstring表示touchMajor轴。
touchMinorstring表示touchMinor轴。
toolMinorstring表示toolMinor轴。
toolMajorstring表示toolMajor轴。
orientationstring表示orientation轴。
pressurestring表示pressure轴。
xstring表示x轴。
ystring表示y轴。
NULLstring无。

AxisRange

输入设备的轴信息。

系统能力 : 以下各项对应的系统能力均为SystemCapability.MultimodalInput.Input.InputDevice

名称参数类型说明
source[SourceType]轴的输入源类型。
axis[AxisType]轴的类型。
maxnumber轴的最大值。
minnumber轴的最小值。
fuzz9+number轴的模糊值。
flat9+number轴的基准值。
resolution9+number轴的分辨率。

SourceType

定义这个轴的输入源类型。比如鼠标设备可上报x轴事件,则x轴的源就是鼠标。

系统能力 :以下各项对应的系统能力均为SystemCapability.MultimodalInput.Input.InputDevice

名称参数类型说明
keyboardstring表示输入设备是键盘。
touchscreenstring表示输入设备是触摸屏。
mousestring表示输入设备是鼠标。
trackballstring表示输入设备是轨迹球。
touchpadstring表示输入设备是触摸板。
joystickstring表示输入设备是操纵杆

ChangedType

定义监听设备热插拔事件。

系统能力 :以下各项对应的系统能力均为SystemCapability.MultimodalInput.Input.InputDevice

名称参数类型说明
addstring表示输入设备插入。
removestring表示输入设备移除。HarmonyOSOpenHarmony鸿蒙文档籽料:mau123789是v直接拿

搜狗高速浏览器截图20240326151547.png

KeyboardType9+

定义键盘输入设备的类型。

系统能力 :以下各项对应的系统能力均为SystemCapability.MultimodalInput.Input.InputDevice

名称参数类型说明
NONEnumber0表示无按键设备。
UNKNOWNnumber1表示未知按键设备。
ALPHABETIC_KEYBOARDnumber2表示全键盘设备。
DIGITAL_KEYBOARDnumber3表示小键盘设备。
HANDWRITING_PENnumber4表示手写笔设备。
REMOTE_CONTROLnumber5表示遥控器设备。

审核编辑 黄宇

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • 鸿蒙
    +关注

    关注

    60

    文章

    2858

    浏览量

    45347
收藏 人收藏
加入交流群
微信小助手二维码

扫码添加小助手

加入工程师交流群

    评论

    相关推荐
    热点推荐

    设备管理系统软件有哪些

    设备管理系统软件有哪些,下面是 设备管理软件功能摘要的NLP颜色标记版,欢迎对比查看素版设备管理软件功能摘要,有想法反映留言,谢谢~~预测\color{#D2691E}预测预测性\color
    发表于 07-12 07:01

    设备管理云平台是什么?有什么功能?

    设备管理云平台:现代化企业的重要解决方案 随着科技的迅速发展和企业规模的扩大,设备数量和种类也随之增加,设备管理变得愈加复杂。传统的管理方法已经无法满足企业的需求,而
    的头像 发表于 09-20 16:39 2660次阅读

    基于RFID油井设备管理手持机的开发研究

    电子发烧友网站提供《基于RFID油井设备管理手持机的开发研究.pdf》资料免费下载
    发表于 10-23 09:35 0次下载
    基于RFID油井<b class='flag-5'>设备管理</b>手持机的<b class='flag-5'>开发</b>研究

    鸿蒙开发接口定制管理:【@ohos.enterpriseDeviceManager (企业设备管理)】

    以异步方法根据给定的包名和类名激活设备管理员应用,使用Callback形式返回是否激活成功。
    的头像 发表于 06-05 09:24 1194次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>开发</b>接口定制<b class='flag-5'>管理</b>:【@<b class='flag-5'>ohos</b>.enterpriseDeviceManager (企业<b class='flag-5'>设备管理</b>)】

    鸿蒙开发设备管理ohos.deviceInfo 设备信息

    面向特定开发者发布的早期预览版本,不承诺API稳定性。 - Beta:面向开发者公开发布的Beta版本,不承诺API稳定性。
    的头像 发表于 07-01 16:33 1267次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>开发</b><b class='flag-5'>设备管理</b>:<b class='flag-5'>ohos</b>.deviceInfo <b class='flag-5'>设备</b>信息

    鸿蒙开发设备管理ohos.multimodalInput.inputEvent 输入事件

    InputEvent模块描述了设备上报的基本事件。
    的头像 发表于 07-02 17:44 608次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>开发</b><b class='flag-5'>设备管理</b>:<b class='flag-5'>ohos.multimodalInput</b>.inputEvent <b class='flag-5'>输入</b>事件

    鸿蒙开发设备管理ohos.multimodalInput.keyCode 键值

    KeyCode模块提供了按键类设备的键值。
    的头像 发表于 07-01 22:14 1003次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>开发</b><b class='flag-5'>设备管理</b>:<b class='flag-5'>ohos.multimodalInput</b>.keyCode 键值

    鸿蒙开发设备管理ohos.multimodalInput.keyEvent 按键输入事件

    KeyEvent模块提供了设备可以上报的按键事件。
    的头像 发表于 07-02 17:25 893次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>开发</b><b class='flag-5'>设备管理</b>:<b class='flag-5'>ohos.multimodalInput</b>.keyEvent 按键<b class='flag-5'>输入</b>事件

    鸿蒙开发设备管理ohos.multimodalInput.mouseEvent 鼠标输入事件

    设备上报的鼠标事件。
    的头像 发表于 07-03 09:20 932次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>开发</b><b class='flag-5'>设备管理</b>:<b class='flag-5'>ohos.multimodalInput</b>.mouseEvent 鼠标<b class='flag-5'>输入</b>事件

    鸿蒙开发设备管理ohos.multimodalInput.touchEvent 触摸输入事件

    设备上报的触屏事件。
    的头像 发表于 07-03 09:16 806次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>开发</b><b class='flag-5'>设备管理</b>:<b class='flag-5'>ohos.multimodalInput</b>.touchEvent 触摸<b class='flag-5'>输入</b>事件

    鸿蒙开发设备管理ohos.usb USB管理

    本模块主要提供管理USB设备的相关功能,包括查询USB设备列表、批量数据传输、控制命令传输、权限控制等。
    的头像 发表于 07-05 17:34 2112次阅读
    <b class='flag-5'>鸿蒙</b><b class='flag-5'>开发</b><b class='flag-5'>设备管理</b>:<b class='flag-5'>ohos</b>.usb USB<b class='flag-5'>管理</b>

    设备管理系统:是什么、谁需要、推荐设备管理系统

    设备管理系统(EMS)在企业管理中愈发重要。中设智控设备管理系统以全生命周期管理为主,涵盖预算、采购、维护等功能,支持移动端应用,降低备件储备,提高
    的头像 发表于 08-01 11:23 2078次阅读
    <b class='flag-5'>设备管理</b>系统:是什么、谁需要、推荐<b class='flag-5'>设备管理</b>系统

    设备管理流程优化的优势

    设备管理对企业生产效率、产品质量、成本控制和安全生产起着关键作用。但设备管理面临挑战,如种类繁多、数量庞大、位置分散等。因此,企业应采用科学的设备管理方法,建立设备管理系统,跟踪
    的头像 发表于 09-05 10:34 920次阅读
    <b class='flag-5'>设备管理</b>流程优化的优势

    基于物联网的设备管理

    物联网设备管理的重要性日益凸显,设备数量激增带来数据泄露风险。加强设备安全性、软件升级与修复、身份验证和互操作性是关键。物联网设备管理需要跨异构设备
    的头像 发表于 09-10 11:04 1357次阅读
    基于物联网的<b class='flag-5'>设备管理</b>

    设备管理系统,终结设备管理难题

    设备管理系统已突破传统工具定位,进化为企业资产管理的数字神经中枢。通过"物联感知-智能分析-决策优化"的闭环体系,实现设备管理从被动响应到主动预防、从经验驱动到数据驱动的根本转变。
    的头像 发表于 03-04 10:51 942次阅读
    <b class='flag-5'>设备管理</b>系统,终结<b class='flag-5'>设备管理</b>难题