4

プログラムでマウスカーソルを移動するときは、250ミリ秒の遅延ではなく、リアルタイムでイベントが発生するように設定CGSetLocalEventsSuppressionIntervalする必要があります。0

残念ながら、SnowLeopardではCGSetLocalEventsSuppressionInterval非推奨としてマークされています。

別の方法は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その機能に必要なものを手に入れることができるかということだと思います。

これは、ユーザーの通常のマウスの動きのイベントソースですか?または、カーソルを手動でワープする場合はどうなりますか?

4

2 に答える 2

4

イベントソースはどこにも説明されていないようで、誰もそれらの使い方を知りません。

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

ワープ呼び出しの直後にCGAssociateMouseAndMouseCursorPosition(true)を呼び出して、Quartzイベントシステムにこの特定のワープの遅延をドロップさせます。

于 2013-07-09T11:24:56.400 に答える
3

この問題を解決したことはありますか?

CGEventCreateSourceFromEvent(...)を使用してCGEventRefからCGEventSourceRefを作成しようとしましたか?

于 2012-07-23T15:06:36.953 に答える