我在这里的法典把 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);
}