是否已弃用NXOpenEventStatus?

时间:2018-04-05 19:08:04

标签: objective-c macos cocoa

我需要在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;
}

1 个答案:

答案 0 :(得分:3)

由于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...个常量。