2016-07-29 4 views
0

OS X 10.11.5를 마우스 오른쪽 버튼으로 클릭 할 수있는 스크립트를 작성하려고합니다. 나는 이것을 달성하기 위해 Objective-C에 Foundation 프레임 워크를 사용 해왔다. 지금까지 성공적으로 왼쪽 버튼을 클릭 할 수있었습니다.CGPostMouseEvent를 사용한 마우스 오른쪽 버튼 클릭 이벤트

아래 스크립트는 CGPostMouseEvent을 사용하여 왼쪽 클릭을 할 수 있습니다. 해당 설명서는 CGRemoteOperation.h에서 찾을 수 있습니다.

CGPostMouseEvent에서 최종 매개 변수로 boolean_t이 필요하다는 언급이 있습니다.

(태평양 표준시, 1, 1, 0, 1)
(태평양 표준시, 1, 1, (0, 1 : 그러나 나는 내가 아무 소용이 PARAMS 다음과 같은 조합을 시도, 그게 무슨 뜻인지 확실하지 않다))
(pt, 1, 1, 2)

오른쪽 클릭을 트리거하는 CGPostMouseEvent의 올바른 최종 매개 변수는 무엇입니까?

#import <Foundation/Foundation.h> 
#import <ApplicationServices/ApplicationServices.h> 


int main(int argc, char *argv[]) { 
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
    NSUserDefaults *args = [NSUserDefaults standardUserDefaults]; 
    // grabs command line arguments -x and -y 
    // 
    int x = [args integerForKey:@"x"]; 
    int y = [args integerForKey:@"y"]; 


    // The data structure CGPoint represents a point in a two-dimensional 
    // coordinate system. Here, X and Y distance from upper left, in pixels. 
    // 
    CGPoint pt; 
    pt.x = x; 
    pt.y = y; 


    // This is where the magic happens. See CGRemoteOperation.h for details. 
    // 
    // CGPostMouseEvent(CGPoint  mouseCursorPosition, 
    //     boolean_t  updateMouseCursorPosition, 
    //     CGButtonCount buttonCount, 
    //     boolean_t  mouseButtonDown, ...) 
    // 
    // So, we feed coordinates to CGPostMouseEvent, put the mouse there, 
    // then click and release. 
    // 

    CGPostMouseEvent(pt, 1, 1, 1); 
    CGPostMouseEvent(pt, 1, 1, 0); 


    [pool release]; 
    return 0; 
} 
+0

Mac OS 10.6에서는'CGPostMouseEvent'가 사용되지 않습니다. – Willeke

답변

1

CGPostMouseEvent은 varargs를 사용하여 왼쪽 마우스 버튼 이외의 버튼 상태를 전달합니다. mouseButtonDown 매개 변수는 마우스 왼쪽 버튼의 작동 여부 만 나타냅니다. 다른 버튼의 상태는 mouseButtonDown 다음에 함수 서명의 varargs 부분에 전달되어야합니다. buttonCount 인수의 경우 왼쪽 버튼을 포함하여 전달중인 총 버튼 상태 수를 전달해야합니다.

다음 시퀀스는 마우스 오른쪽 단추에 대한 마우스 작동 이벤트 다음에 마우스 작동 이벤트를 게시해야합니다. 말했다

CGPostMouseEvent(pt, 1, 2, 0, 1); 
CGPostMouseEvent(pt, 1, 2, 0, 0); 

, CGPostMouseEvent은 몇 시간 동안 사용되지 않습니다. 그 대체품 인 CGEventCreateMouseEventCGEventPost을 결합하면 사용하기가 더 쉽습니다.

+0

대단히 감사합니다! – hotPocket

관련 문제