Issue #125 Explicitly request Input Monitoring and error if denied

This commit is contained in:
Mat Sutcliffe
2021-10-30 21:37:00 +01:00
parent b9544ead61
commit 8358dd7e98
4 changed files with 34 additions and 1 deletions

View File

@@ -146,6 +146,10 @@ namespace BlackInput
bool CKeyboardMacOS::init()
{
if (!CMacOSInputUtils::requestAccess())
{
CLogMessage(this).error(u"Access denied for keyboard input monitoring");
}
m_hidManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
CFMutableArrayRef matchingArray = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
@@ -174,7 +178,16 @@ namespace BlackInput
IOHIDManagerRegisterInputValueCallback(m_hidManager, valueCallback, this);
IOHIDManagerScheduleWithRunLoop(m_hidManager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
IOHIDManagerOpen(m_hidManager, kIOHIDOptionsTypeNone);
const auto result = IOHIDManagerOpen(m_hidManager, kIOHIDOptionsTypeNone);
if (result == kIOReturnSuccess)
{
CLogMessage(this).debug(u"Initialized");
}
else
{
CLogMessage(this).error(u"Failed to open HID manager for keyboard monitoring");
}
return true;
}