2012-04-23 2 views
0

GSEvent로 터치 이벤트를 내 앱에 보내려면 GSCopyPurpleSystemEventPort()로 mach_port_t를 가져 오십시오.GSEvent를 사용하여 터치 이벤트를 보내지 만 올바르지 않습니다.

ApplicationDidFinishLaunch : 옵션이 완료되면 전송 기능이 시작되었습니다. 앱이 UIControlView 앱입니다.

다음과 같은

코드 :

void handleMouseEventAtPoint(CGPoint point, int buttons) 
{ 
    // NOTE: Must store button state for comparision, port for 
    //  mouse dragging and button up 
    static int buttons_; 
    static mach_port_t port_; 

    int diff = buttons_^buttons; 
    bool twas = ((buttons_ & 0x1) != 0); 
    bool tis = ((buttons & 0x1) != 0); 
    buttons_ = buttons; 

    // Round point values to prevent subpixel coordinates 
    point.x = roundf(point.x); 
    point.y = roundf(point.y); 

    // Check for mouse button events 
    mach_port_t purple; 

    if ((diff & 0x10) != 0) { 
     // Simulate Headset button press 
     struct GSEventRecord record; 

     memset(&record, 0, sizeof(record)); 

     record.type = (buttons & 0x4) != 0 ? 
     kGSEventHeadsetButtonDown : 
     kGSEventHeadsetButtonUp; 

     record.timestamp = GSCurrentEventTimestamp(); 
     FixRecord(&record); 
     GSSendSystemEvent(&record); 
    } 

    if ((diff & buttonThree) != 0) { 
     // Simulate Home button press 
     struct GSEventRecord record; 

     memset(&record, 0, sizeof(record)); 

     record.type = (buttons & buttonThree) != 0 ? 
     kGSEventMenuButtonDown : 
     kGSEventMenuButtonUp; 

     record.timestamp = GSCurrentEventTimestamp(); 
     FixRecord(&record); 
     GSSendSystemEvent(&record); 
    } 

    if ((diff & buttonTwo) != 0) 
    { 
     // Simulate Sleep/Wake button press 
     struct GSEventRecord record; 

     memset(&record, 0, sizeof(record)); 

     record.type = (buttons & buttonTwo) != 0 ? 
     kGSEventLockButtonDown : 
     kGSEventLockButtonUp; 

     record.timestamp = GSCurrentEventTimestamp(); 
     FixRecord(&record); 
     GSSendSystemEvent(&record); 
    } 

    if (twas != tis || tis) { 
     // Main (left button) state changed, or was dragged 
     struct { 
      struct GSEventRecord record; 
      struct 
      { 
       struct GSEventRecordInfo info; 
       struct GSPathInfo path; 
      } data; 
     } event; 

     memset(&event, 0, sizeof(event)); 

     event.record.type = kGSEventHand; 
     event.record.windowLocation = point; 
     event.record.timestamp = GSCurrentEventTimestamp(); 
     event.record.infoSize = sizeof(event.data); 

     event.data.info.handInfo.type = twas == tis ? 
     kGSHandInfoTypeTouchDragged : 
     tis ? 
     kGSHandInfoTypeTouchDown : 
     kGSHandInfoTypeTouchUp; 

     event.data.info.handInfo._0x44 = 0x1; 
     event.data.info.handInfo._0x48 = tis ? 0x1 : 0x0; 

     event.data.info.pathPositions = 1; 

     event.data.path.pathIndex = 0x01; 
     event.data.path.pathIdentity = 0x02; 
     event.data.path.pathProximity = tis ? 0x03 : 0x00; 
     event.data.path.pathLocation = event.record.windowLocation; 

     if (twas != tis && tis) 
     { 
      // Button down and was not down before 
      port_ = 0; 

      CAWindowServer *server; 

      server = [CAWindowServer serverIfRunning]; 
      char svrptrstr [255]; 
      sprintf(svrptrstr, "%p", server); 

      NSLog(@"One!"); 

      if (server = [CAWindowServer serverIfRunning]) 
       //if (true) 
      { 
       NSLog(@"Two!"); 
       //NSArray *displays([server displays]); 
       NSArray *displays = [server displays]; 
       if (displays != nil && [displays count] != 0) 
       { 
        NSLog(@"Three!"); 
        //CAWindowServer *display; 
        if (CAWindowServerDisplay *display = [displays objectAtIndex:0]) 
        { 
         NSLog(@"Four!"); 
         port_ = [display clientPortAtPosition:point]; 
        } 
       } 
      } 

      if (port_ == 0) 
      { 
       // Is SpringBoard 
       if (purple == 0) 
       { 
        purple = GSGetPurpleSystemEventPort(); 
        port_ = purple; 

       } 
      } 
     } 

     FixRecord(&event.record); 

     GSSendEvent(&event.record, port_); 
     NSLog(@"Event sent!"); 
     //GSSendSystemEvent(&event.record); 
     //GSSendEvent(&event.record, purple); 
    } 

    if (purple != 0 && PurpleAllocated) 
    { 
     mach_port_deallocate(mach_task_self(), purple); 
     NSLog(@"Deallocated mach_port!"); 
    } 
} 

하지만 탈옥 아이 패드 2 (iOS5.01)에서 앱 시작, 클릭 이벤트가 수행 된 경우에는이 모든 클릭 결과,의 debug.log를가 될 것 없다.

누가 내가 놓친 걸 나에게 말할 수 있습니까?

+0

이것에 대한 진행 상황이 있습니까? iOS 5.0 이상에 터치 이벤트를 보낼 수 있었습니까? 그렇다면 우리에게도 알려주십시오. – user2197966

답변

0

나는이 코드를 다른 곳에서 보았습니다 (마우스 클릭을 iPhone/iPad 탭으로 변환 한 응용 프로그램에서 생각한 것 같습니다). 여기서 문제는 코드 또는 포트가 아니라 보내는 이벤트 구조입니다. 이것은 iOS 3.0 용 GSevent 구조이며 iOS 5.0 용 구조는 아닙니다. 그것은 구조뿐만 아니라 값과 태그에서도 변했습니다. UIEvents를 받아서 GSEvents로 변환하고 내용을 살펴 보는 것이 좋습니다.

+0

iOS 5.0 온라인 GSEvent 구조에 대한 정보가 있습니까? 그렇다면 URL을 제공해 주시겠습니까? – AngelWing

+0

아니요, 온라인은 없습니다. 가장 멀리 갈 수있는 곳은 KennyTM의 개인 API 라이브러리입니다. 모든 UIEvent를 받고이를 GSEvent로 변환하는 것이 좋습니다. 그런 다음 수신 한 값을 자세히보고 비슷한 구조로 보내십시오. –

+0

나는 touchesBegan : withEvent :를 오버라이드하고이를 강제로 GSEvent로 변환하여 구조를 보았다.하지만이 정보가 잘못되었다고 생각한다. 강제로 GSEvent로 변환 할 수 없을 수도있다. – AngelWing

관련 문제