GSSendEvent - Inject Touch Event iOS

后端 未结 2 430
梦谈多话
梦谈多话 2020-12-05 16:35

I want to inject touch event in iPhone. I get the coordinates of touch event via network socket. GSSendEvent seems to be good choice. However, it needs GSEventRecord as one

2条回答
  •  北海茫月
    2020-12-05 17:00

    Answer from EntryLevelDev is correct, but some of the value is not so important. I got the below codes from somewhere else and have done some try and errors, here is my codes(worked for till latested ios6).

    And is anyone working on this for IOS7 now? I could not get it to work. see my post here:With GSCopyPurpleNamedPort(appId) in GraphicsServices deprecated in IOS7, what is the alternative approach?

    static int prev_click = 0;
    
    if (!click && !prev_click)
    {
        //which should never enter
        NSLog(@"***error, postHandEvent cancel");
        return;
    }
    
    CGPoint location = CGPointMake(x, y);
    
    struct GSTouchEvent {
        GSEventRecord record;
        GSHandInfo    handInfo;
    } * event = (struct GSTouchEvent*) &touchEvent;
    bzero(touchEvent, sizeof(touchEvent));
    
    event->record.type = kGSEventHand;
    event->record.windowLocation = location;
    event->record.timestamp = GSCurrentEventTimestamp();
    //NSLog(@"Timestamp GSCurrentEventTimestamp: %llu",GSCurrentEventTimestamp());
    event->record.infoSize = sizeof(GSHandInfo) + sizeof(GSPathInfo);
    event->handInfo.type = getHandInfoType(prev_click, click);
    
    //must have the following line
    event->handInfo.x52 = 1;
    
    //below line is for ios4
    //event->handInfo.pathInfosCount = 1;
    
    
    bzero(&event->handInfo.pathInfos[0], sizeof(GSPathInfo));
    event->handInfo.pathInfos[0].pathIndex     = 2;
    //following 2 lines, they are by default
    event->handInfo.pathInfos[0].pathMajorRadius = 1.0;
    event->handInfo.pathInfos[0].pathPressure = 1.0;
    
    //event->handInfo.pathInfos[0].pathIdentity  = 2;
    event->handInfo.pathInfos[0].pathProximity = click ? 0x03 : 0x00;
    //event->handInfo.pathInfos[0].pathProximity = action;
    event->handInfo.pathInfos[0].pathLocation  = location;
    
    // send GSEvent 
    GSEventRecord *event1 = (GSEventRecord*) event;
    sendGSEvent(event1);
    

提交回复
热议问题