Linux 输入子系统事件类型宏解释 (UI_SET_EVBIT, UI_SET_KEYBIT, 等)
这些宏的用途是设置 Linux 内核输入子系统的事件类型。具体来说:
- UI_SET_EVBIT:设置支持的事件类型。通常包括 EV_SYN、EV_KEY、EV_REL、EV_ABS 等。
- UI_SET_KEYBIT:设置支持的按键类型。
- UI_SET_PROPBIT:设置支持的属性类型。
- UI_SET_ABSBIT:设置支持的绝对坐标类型。
- UI_SET_RELBIT:设置支持的相对坐标类型。
- UI_SET_MSCBIT:设置支持的杂项类型。
- UI_SET_LEDBIT:设置支持的 LED 类型。
- UI_SET_SWBIT:设置支持的开关类型。
- UI_SET_FFBIT:设置支持的重复类型。
代码示例:
void VirtualDeviceBuilder::SetSupportedEvents()
{
static const std::map<int32_t, std::function<std::vector<uint32_t>()>> uinputTypes { { UI_SET_EVBIT,
std::bind(&VirtualDeviceBuilder::GetEventTypes, this) },
{ UI_SET_KEYBIT, std::bind(&VirtualDeviceBuilder::GetKeys, this) },
{ UI_SET_PROPBIT, std::bind(&VirtualDeviceBuilder::GetProperties, this) },
{ UI_SET_ABSBIT, std::bind(&VirtualDeviceBuilder::GetAbs, this) },
{ UI_SET_RELBIT, std::bind(&VirtualDeviceBuilder::GetRelBits, this) },
{ UI_SET_MSCBIT, std::bind(&VirtualDeviceBuilder::GetMiscellaneous, this) },
{ UI_SET_LEDBIT, std::bind(&VirtualDeviceBuilder::GetLeds, this) },
{ UI_SET_SWBIT, std::bind(&VirtualDeviceBuilder::GetSwitches, this) },
{ UI_SET_FFBIT, std::bind(&VirtualDeviceBuilder::GetRepeats, this) } };
for (const auto &setEvents : uinputTypes) {
const auto &events = setEvents.second();
for (const auto &e : events) {
if (ioctl(fd_, setEvents.first, e) < 0) {
FI_HILOGE("Failed while setting event type");
}
}
}
}
这段代码使用 C++ 中的 std::map 和 std::bind 来简洁地实现事件类型的设置。每个宏对应一个 std::function,该函数负责返回相应的事件类型列表。通过 ioctl 系统调用将这些事件类型信息传递给 Linux 内核。
原文地址: https://www.cveoy.top/t/topic/n6wr 著作权归作者所有。请勿转载和采集!