2013-05-08 8 views
1

, 나는 그것이 전체 화면 모드에 있다면 그래서 지금,이 응답하지 않습니다, 응용 프로그램이 종료 일으키는 눌러 명령 + Q의 효과를 사용하지 않도록 관리 종료 키보드 단축키. 어떻게 MAC OS X 대물 C 코드 명령 + Q + 시프트 명령을 폐기? 나는 맥 OS X에서 스크린 세이버 시뮬레이터를 구현하기 위해 노력하고있어

하지만, 내 문제는 모든 응용 프로그램 및 시스템의 로그 기록을 종료 경고 맥스 OS X의 확인 대화 상자를 팝업 (명령 + 시프트 + Q)의 바로 가기를 취급합니다.

사람은 전체 화면 모드에있는 동안 명령 + Shift + Q 바로 가기의 효과를 방지 나를 도와 드릴까요?

감사

답변

2

이것은 당신의 applicationDidFinishedLoad 기능에

먼저이 질문에 이벤트 탭을 생성하는 코드의 평화를 추가하고 현재 실행 루프에서 이벤트 탭을 추가하기위한 가장 좋은 대답이다

CFMachPortRef  eventTap; 
CGEventMask  eventMask; 
CFRunLoopSourceRef runLoopSource; 

// Create an event tap. We are interested in key presses. 
eventMask = ((1 << kCGEventKeyDown) | (1 << kCGEventKeyUp)); 
eventTap = CGEventTapCreate(kCGSessionEventTap, kCGHeadInsertEventTap, 0, 
          eventMask, myCGEventCallback, NULL); 
if (!eventTap) { 
    fprintf(stderr, "failed to create event tap\n"); 
    exit(1); 
} 

// Create a run loop source. 
runLoopSource = CFMachPortCreateRunLoopSource(
        kCFAllocatorDefault, eventTap, 0); 

// Add to the current run loop. 
CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, 
        kCFRunLoopCommonModes); 

// Enable the event tap. 
CGEventTapEnable(eventTap, true); 

는 클래스에, 당신은이

CGEventRef myCGEventCallback(CGEventTapProxy proxy, CGEventType type, 
       CGEventRef event, void *refcon) 
    { 
// Paranoid sanity check. 
// type will be key down or key up, you can discard the command + q by setting the  kecode to be -1 like this 

if (((type == kCGEventKeyDown) || (type == kCGEventKeyUp))) 
{ 
    CGEventSetIntegerValueField(
           event, kCGKeyboardEventKeycode, (int64_t)-1); 
    return event; 
} 

// The incoming keycode. 
CGKeyCode keycode = (CGKeyCode)CGEventGetIntegerValueField(
            event, kCGKeyboardEventKeycode); 

// Swap 'a' (keycode=0) and 'z' (keycode=6). 
if (keycode == (CGKeyCode)0) 
    keycode = (CGKeyCode)6; 
else if (keycode == (CGKeyCode)6) 
    keycode = (CGKeyCode)0; 

// Set the modified keycode field in the event. 
CGEventSetIntegerValueField(
    event, kCGKeyboardEventKeycode, (int64_t)keycode); 

// We must return the event for it to be useful. 
return event; 
} 
0123처럼 myCGEventCallback을 호출 된 함수를 호출을 다시 구현할 수 있습니다원래의 코드에 대한

에게 Check Here

감사