#鸿蒙通关秘籍#如何在鸿蒙中使用HID DDK接口创建设备?

HarmonyOS
5天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
CLI梦回吹角连营

首先需要在CMakeLists.txt文件中添加以下库支持HID的操作:

bash libhid.z.so

然后,包含必须的头文件:

c #include <hid/hid_ddk_api.h> #include <hid/hid_ddk_types.h>

接下来,使用以下代码创建设备并获取设备ID:

c std::vector<Hid_DeviceProp> deviceProp = {HID_PROP_DIRECT}; std::string deviceName = "keyboard"; Hid_Device hidDevice = { .deviceName = deviceName.c_str(), .vendorId = 0x6006, .productId = 0x6006, .version = 1, .bustype = 3, .properties = deviceProp.data(), .propLength = (uint16_t)deviceProp.size() }; std::vector<Hid_EventType> eventType = {HID_EV_ABS, HID_EV_KEY, HID_EV_SYN, HID_EV_MSC}; Hid_EventTypeArray eventTypeArray = {.hidEventType = eventType.data(), .length = (uint16_t)eventType.size()}; Hid_EventProperties hidEventProp = { .hidEventTypes = eventTypeArray, }; int32_t deviceId = OH_Hid_CreateDevice(&hidDevice, &hidEventProp);

分享
微博
QQ
微信
回复
5天前
相关问题