替换已弃用的NXOpenEventStatus吗? [英] Replacement for deprecated NXOpenEventStatus?

查看:137
本文介绍了替换已弃用的NXOpenEventStatus吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获得OSX 10.13上鼠标的跟踪速度.我在互联网上找到了此代码,但不建议使用NXOpenEventStatus(IOHIDGetAccelerationWithKey也是如此),还有其他方法吗?

I need to get the tracking speed of the mouse on OSX 10.13. I found this code on the internet but NXOpenEventStatus is deprecated (as is IOHIDGetAccelerationWithKey), is there an alternative way?

#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发行版的一部分,因此您可以

Since NXOpenEventStatus and IOHIDGetAccelerationWithKey are both part of the open-source IOKit distribution, you can look at how they're implemented. It turns out we can do what those functions do, using only non-deprecated functions.

要将其精简到最低限度,您可以像以下那样获得有关HID系统属性的字典:

To boil it down to the bare minimum, you can get a dictionary of the HID system's properties like this:

#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上为我):

Output (for me on 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...常量.

The kIOHIDMouseAccelerationType constant has value HIDMouseAcceleration. I also see HIDPointerAcceleration and HIDTrackpadAcceleration in there. There are kIOHID... constants for those too.

这篇关于替换已弃用的NXOpenEventStatus吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆