【发布时间】:2019-10-10 12:14:37
【问题描述】:
函数 IOHIDGetAccelerationWithKey 和 IOHIDSetAccelerationWithKey 自 macOS 10.12 起已弃用,因此我尝试使用其他 IO* 方法来实现相同的功能。
我从未使用过 IOKit,因此,我所能做的就是在谷歌上搜索功能并尝试让它工作。
现在我发现了这个:Can't edit IORegistryEntry,其中有一个如何更改TrackpadThreeFingerSwipe 属性的示例,但是它使用了一个没有为我定义的函数:getEVSHandle。谷歌搜索只显示它应该在 MachineSettings 框架中找到,但是我似乎无法在 Xcode 11 中添加任何“MachineSettings”框架。
我该怎么办?当前代码如下:
#import <Foundation/Foundation.h>
#import <IOKit/hidsystem/IOHIDLib.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSInteger value = -65536;
CFNumberRef number = CFNumberCreate(kCFAllocatorDefault, kCFNumberNSIntegerType, &value);
CFMutableDictionaryRef propertyDict = CFDictionaryCreateMutable(kCFAllocatorDefault, 1, NULL, NULL);
CFDictionarySetValue(propertyDict, @"HIDMouseAcceleration", number);
io_connect_t connect = getEVSHandle(); // ???
if (!connect)
{
NSLog(@"Unable to get EVS handle");
}
res = IOConnectSetCFProperties(connect, propertyDict);
if (res != KERN_SUCCESS)
{
NSLog(@"Failed to set mouse acceleration (%d)", res);
}
IOObjectRelease(service);
CFRelease(propertyDict);
}
return 0;
}
【问题讨论】:
-
MachineSettings 是一个私有框架,可以在 /System/Library/PrivateFrameworks 中找到
-
是否有相关文档?例如。
getEVSHandle在做什么?我还在stackoverflow.com/questions/49679753/… 中找到了IORegistryEntryFromPath,它可以检索鼠标加速,但不能设置它。我还找到了IOServiceOpen,但是我不确定如何在owningTask和type参数方面使用它(这似乎被getEVSHandle所覆盖?)。
标签: objective-c macos kernel mouse iokit