English 中文(简体)
为什么会造成拖延? 如果没有,情况如何?
原标题:Why is CGWarpMouseCursorPosition causing a delay? If it is not, what is?

我在这里的法典把 mo局限于屏幕上的一个区域,它的工作相对较好,只有一个大问题。 潮use在沿区域边缘移动时,会得到清洁/友好的移动,而是以非常巧妙的方式跳出,我认为这可能是由于CGWarpMouseCursorPosition造成每个“战争”。

www.un.org/Depts/DGACM/index_spanish.htm 任何人都能够说,这是否在我的法典中引起这种拖延,或者事实上是 mo忙的。 如果是摩擦功能的话,我是否能够顺利地搬迁 mo? 我在闪电中做了同样的事情,而且它无休止地运作,我知道, lo子仅仅花了这么多时间执行,它减缓了事情,因为它只剩下4或5次。

CGEventRef 
mouse_filter(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon) {


    CGPoint point = CGEventGetLocation(event);

    float tX = point.x;
    float tY = point.y;

    if( tX <= 700 && tX >= 500 && tY <= 800 && tY >= 200){
        // target is inside O.K. area, do nothing
    }else{

    CGPoint target; 

    //point inside restricted region:
    float iX = 600; // inside x
    float iY = 500; // inside y

    // delta to midpoint between iX,iY and tX,tY
    float dX;
    float dY;

    float accuracy = .5; //accuracy to loop until reached

    do {
        dX = (tX-iX)/2;
        dY = (tY-iY)/2;

        if((tX-dX) <= 700 && (tX-dX) >= 500 && (tY-dY) <= 800 && (tY-dY) >= 200){
            iX += dX;
            iY += dY;
        } else {
            tX -= dX;
            tY -= dY;
        }

    } while (abs(dX)>accuracy || abs(dY)>accuracy);

        target = CGPointMake(roundf(tX), roundf(tY));
        CGWarpMouseCursorPosition(target);

    }



    return event;
}

int
main(int argc, char *argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    CFRunLoopSourceRef runLoopSource;
    CGEventMask event_mask;
    event_mask = CGEventMaskBit(kCGEventMouseMoved) | CGEventMaskBit(kCGEventLeftMouseDragged) | CGEventMaskBit(kCGEventRightMouseDragged) | CGEventMaskBit(kCGEventOtherMouseDragged);

    CFMachPortRef eventTap = CGEventTapCreate(kCGHIDEventTap, kCGHeadInsertEventTap, 0, event_mask, mouse_filter, NULL);

    if (!eventTap) {
        NSLog(@"Couldn t create event tap!");
        exit(1);
    }

    runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0);

    CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopCommonModes);

    CGEventTapEnable(eventTap, true);

    CFRunLoopRun();

    CFRelease(eventTap);
    CFRelease(runLoopSource);
    [pool release];

    exit(0);
}
最佳回答

As you discovered, CGSetLocalEventsSuppressionInterval fixes your problem.

However, it s deprecated as of 10.6. the Apple docs state:

This function is not recommended for general use because of undocumented special cases and undesirable side effects. The recommended replacement for this function is CGEventSourceSetLocalEventsSuppressionInterval, which allows the suppression interval to be adjusted for a specific event source, affecting only events posted using that event source.

遗憾的是,替换代码“CGEventSourceSet LocalEventsSuppressionInterval没有使用

相反,在战争之后立即使用:

CGPoint warpPoint = CGPointMake(42, 42);
CGWarpMouseCursorPosition(warpPoint);
CGAssociateMouseAndMouseCursorPosition(true);

The documentation makes no mention of this behavior, but it appears to cancel the suppression interval after the warp.

问题回答

I could get CGEventSourceSetLocalEventsSuppressionInterval to work with CGWarpMouseCursorPosition the following way:

auto eventSourceRef = CGEventSourceCreate(kCGEventSourceStateCombinedSessionState);
CGEventSourceSetLocalEventsSuppressionInterval(eventSourceRef, 0);

这项工程用进行。 虽然对我没有帮助。





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签