gpt4 book ai didi

objective-c - 替换已弃用的 NXOpenEventStatus?

转载 作者:行者123 更新时间:2023-12-03 16:56:35 27 4
gpt4 key购买 nike

我需要获取 OSX 10.13 上鼠标的跟踪速度。我在互联网上找到了这段代码,但 NXOpenEventStatus 已被弃用(IOHIDGetAccelerationWithKey 也是如此),有其他方法吗?

#include <stdio.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/hidsystem/IOHIDLib.h>
#include <IOKit/hidsystem/IOHIDParameter.h>
#include <IOKit/hidsystem/event_status_driver.h>

int main()
{
kern_return_t kr;
double trackpadAcceleration, mouseAcceleration;
NXEventHandle h = 0;

h = NXOpenEventStatus();

if (h == nil)
return -1;


kr = IOHIDGetAccelerationWithKey( h, CFSTR(kIOHIDMouseAccelerationType), &mouseAcceleration);


return 0;
}

最佳答案

由于 NXOpenEventStatusIOHIDGetAccelerationWithKey 都是开源 IOKit 发行版的一部分,因此您可以look at how they're implemented 。事实证明,我们可以只使用未弃用的函数来完成这些函数的功能。

为了将其归结为最低限度,您可以获得 HID 系统属性的字典,如下所示:

#import <Foundation/Foundation.h>
#import <IOKit/hidsystem/IOHIDLib.h>

int main(int argc, const char * argv[]) {
@autoreleasepool {
io_service_t service = IORegistryEntryFromPath(kIOMasterPortDefault, kIOServicePlane ":/IOResources/IOHIDSystem");

CFDictionaryRef parameters = IORegistryEntryCreateCFProperty(service, CFSTR(kIOHIDParametersKey), kCFAllocatorDefault, kNilOptions);
NSLog(@"%@", parameters);

IOObjectRelease(service);
}
return 0;
}

输出(对于 macOS 10.13.4 上的我):

2018-04-05 17:06:55.560590-0500 accel[11924:131983] {
ActuateDetents = 1;
Clicking = 0;
DragLock = 0;
Dragging = 0;
EjectDelay = 0;
FirstClickThreshold = 1;
ForceSuppressed = 0;
HIDClickSpace = (
5,
5
);
HIDClickTime = 500000000;
HIDDefaultParameters = 1;
HIDF12EjectDelay = 250;
HIDFKeyMode = 1;
HIDInitialKeyRepeat = 250000000;
HIDKeyRepeat = 33333333;
HIDKeyboardModifierMappingPairs = (
);
HIDMouseAcceleration = 98304;
HIDMouseKeysOptionToggles = 0;
HIDPointerAcceleration = 45056;
HIDPointerButtonMode = 2;
HIDScrollAcceleration = 20480;
HIDScrollZoomModifierMask = 262144;
HIDSlowKeysDelay = 0;
HIDStickyKeysDisabled = 0;
HIDStickyKeysOn = 0;
HIDStickyKeysShiftToggles = 0;
HIDTrackpadAcceleration = 57344;
HIDWaitCursorFrameInterval = 16666667;
JitterNoClick = 1;
JitterNoMove = 1;
MouseButtonDivision = 55;
MouseButtonMode = TwoButton;
MouseHorizontalScroll = 1;
MouseMomentumScroll = 1;
MouseOneFingerDoubleTapGesture = 0;
MouseTwoFingerDoubleTapGesture = 0;
MouseTwoFingerHorizSwipeGesture = 0;
MouseVerticalScroll = 1;
"OutsidezoneNoAction When Typing" = 1;
"PalmNoAction Permanent" = 1;
"PalmNoAction When Typing" = 1;
SecondClickThreshold = 1;
"Trackpad Jitter Milliseconds" = 192;
TrackpadCornerSecondaryClick = 0;
TrackpadFiveFingerPinchGesture = 0;
TrackpadFourFingerHorizSwipeGesture = 2;
TrackpadFourFingerPinchGesture = 0;
TrackpadFourFingerVertSwipeGesture = 0;
TrackpadHandResting = 1;
TrackpadHorizScroll = 1;
TrackpadMomentumScroll = 1;
TrackpadPinch = 1;
TrackpadRightClick = 1;
TrackpadRotate = 1;
TrackpadScroll = 1;
TrackpadThreeFingerDrag = 0;
TrackpadThreeFingerHorizSwipeGesture = 2;
TrackpadThreeFingerTapGesture = 0;
TrackpadThreeFingerVertSwipeGesture = 0;
TrackpadThreeFingersRightClick = 0;
TrackpadTwoFingerDoubleTapGesture = 1;
TrackpadTwoFingerFromRightEdgeSwipeGesture = 0;
TwofingerNoAction = 1;
USBMouseStopsTrackpad = 0;
"Use Panther Settings for W" = 0;
UserPreferences = 1;
version = 1;
}
Program ended with exit code: 0

kIOHIDMouseAccelerationType 常量的值为 HIDMouseAcceleration。我还在那里看到 HIDPointerAccelerationHIDTrackpadAcceleration 。这些也有 kIOHID... 常量。

另请注意,IOHIDGetAccelerationWithKey 在返回注册表值之前将其除以 65536。 IOHIDSetAccelerationWithKey 执行相反的转换。

关于objective-c - 替换已弃用的 NXOpenEventStatus?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49679753/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com