相关疑难解决方法(0)

使用事件点击消耗OSX鼠标/触控板事件

我正在尝试添加一个事件陷阱来启用/禁用魔术触控板上的事件.我认为这将是直截了当的,即注册事件陷阱,并在需要时通过返回丢弃事件NULL.我们的想法是使用pad进行一些特定的,耗时的数据输入,输入数据的应用程序是第三方的,所以我不能只是添加代码来实现我想要的.所以我想我会监视系统事件,然后通过一堆CGEventCreateKeyboardEvents 发送所需的输入.

问题是返回null似乎没有丢弃事件,更多的调查表明,这不仅限于来自触控板的那些,而且也是我的默认USB鼠标.

我的代码如下.以下是我希望不能移动鼠标,如果我改变(A)使用kCGEventScrollWheelkCGEventLeftMouseDragged然后消耗事件,即滚动或左btn拖动不会发生.这是否意味着并非所有事件都可以丢弃?希望我在这里错过了一些明显的东西

  #define case_print(a) case a: printf("%s - %d\n",#a,a); break;


  CGEventRef eventOccurred(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void* refcon) {
    int subType =  CGEventGetIntegerValueField(event, kCGMouseEventSubtype);
    if (type == NSEventTypeGesture || subType == NX_SUBTYPE_MOUSE_TOUCH) {
        printf("touchpad\n");

        switch(type) {
                case_print(kCGEventNull)
                case_print(kCGEventLeftMouseDown)
                case_print(kCGEventLeftMouseUp)
                case_print(kCGEventRightMouseDown)
                case_print(kCGEventRightMouseUp)
                case_print(kCGEventMouseMoved)
                case_print(kCGEventLeftMouseDragged)
                case_print(kCGEventRightMouseDragged)
                case_print(kCGEventScrollWheel)
                case_print(kCGEventOtherMouseDown)
                case_print(kCGEventOtherMouseUp)
                case_print(kCGEventOtherMouseDragged)
                case_print(kCGEventTapDisabledByTimeout)
                case_print(kCGEventTapDisabledByUserInput)
                case_print(NSEventTypeGesture)
                case_print(NSEventTypeMagnify)
                case_print(NSEventTypeSwipe)
                case_print(NSEventTypeRotate)
                case_print(NSEventTypeBeginGesture)
                case_print(NSEventTypeEndGesture)
            default:
                printf("default: %d\n",type);
                break;    
        }

        event = NULL;
    }  else {
        if (type …
Run Code Online (Sandbox Code Playgroud)

macos cocoa objective-c

6
推荐指数
1
解决办法
4748
查看次数

标签 统计

cocoa ×1

macos ×1

objective-c ×1