【问题标题】:Using `CGEventSourceSetLocalEventsSuppressionInterval` instead of the deprecated `CGSetLocalEventsSuppressionInterval`使用 `CGEventSourceSetLocalEventsSuppressionInterval` 而不是已弃用的 `CGSetLocalEventsSuppressionInterval`
【发布时间】:2012-04-29 02:38:03
【问题描述】:

以编程方式移动鼠标光标时,您必须将 CGSetLocalEventsSuppressionInterval 设置为 0,以便事件实时进入,而不是延迟 250 毫秒。

很遗憾,CGSetLocalEventsSuppressionInterval 在 Snow Leopard 中被标记为已弃用。

替代方案是CGEventSourceSetLocalEventsSuppressionInterval(CGEventSourceRef source, CFTimeInterval seconds); https://developer.apple.com/library/mac/#documentation/Carbon/Reference/QuartzEventServicesRef/Reference/reference.html#//apple_ref/c/func/CGEventSourceSetLocalEventsSuppressionInterval

-(void) mouseMovement:(CGEventRef) newUserMouseMovement
{
    //Move cursor to new position
    CGSetLocalEventsSuppressionInterval(0.0); //Deprecated in OS X 10.6
    CGWarpMouseCursorPosition(NSPointToCGPoint(newMousePosition));
    CGSetLocalEventsSuppressionInterval(0.25); //Deprecated in OS X 10.6

    //--OR--//

    CGEventSourceRef source = ???;
    CGEventSourceSetLocalEventsSuppressionInterval(source, 0.0);
    CGWarpMouseCursorPosition(NSPointToCGPoint(newMousePosition));
    CGEventSourceSetLocalEventsSuppressionInterval(source, 0.25);
}

我无法让后一种方法起作用。

所以我想我的问题是如何获得该功能所需的CGEventSourceRef

它是用户正常鼠标移动的事件源吗?还是为了我手动扭曲光标?

【问题讨论】:

    标签: objective-c macos cocoa macos-carbon


    【解决方案1】:

    事件源似乎在任何地方都没有解释,也没有人知道如何使用它们。

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

    在调用 warp 后立即调用 CGAssociateMouseAndMouseCursorPosition( true ) 以使 Quartz 事件系统降低此特定 warp 的延迟。

    【讨论】:

      【解决方案2】:

      你解决过这个问题吗?

      您是否尝试过使用 CGEventCreateSourceFromEvent(...) 从 CGEventRef 创建 CGEventSourceRef?

      【讨论】:

      • 我无法找到经线的CGEventSourceRef。苹果文档声明经纱“无需生成或发布事件”即可工作,因此我不确定它是否有来源。不过,从我刚刚接受的答案来看,“CGAssociateMouseAndMouseCursorPosition(true);”与经线一起使用!
      猜你喜欢
      • 1970-01-01
      • 2020-02-02
      • 2021-04-20
      • 1970-01-01
      • 1970-01-01
      • 2020-12-13
      • 2013-09-25
      • 2020-12-06
      • 2015-12-26
      相关资源
      最近更新 更多