2

我想在越狱设备上模拟多点触控事件,我试过了GSEvent,我不知道结构的每个字段,所以我只是假设每个 pathInfo 意味着一个手指信息,但没有效果,谁能给我一些帮助?谢谢你非常喜欢。

typedef struct touch {
    int identity;
    int x;
    int y;
    GSHandInfoType type;
} touch;

static void sendTouches(touch touches[])
{

    if (touches_count<1) {
        return;
    }

    uint8_t touchEvent[sizeof(GSEventRecord) + sizeof(GSHandInfo) + sizeof(GSPathInfo)*touches_count];

    // structure of touch GSEvent
    struct GSTouchEvent {
        GSEventRecord record;
        GSHandInfo    handInfo;
    } * event = (struct GSTouchEvent*) &touchEvent;
    bzero(touchEvent, sizeof(touchEvent));

    // set up GSEvent
    event->record.type = kGSEventHand;
    event->record.subtype = kGSEventSubTypeUnknown;
    event->record.windowLocation = CGPointMake(touches[0].x, touches[0].y);
    event->record.timestamp = GSCurrentEventTimestamp();
    event->record.infoSize = sizeof(GSHandInfo) + sizeof(GSPathInfo);
    event->handInfo.type = touches[0].type;
    event->handInfo.x52 = touches_count;
    event->handInfo.pathInfosCount = touches_count;

    for (int i=0; i<touches_count; i++) {
        bzero(&event->handInfo.pathInfos[i], sizeof(GSPathInfo));
        event->handInfo.pathInfos[i].pathIndex     = 1;
        event->handInfo.pathInfos[i].pathIdentity  = 2;
        event->handInfo.pathInfos[i].pathProximity = (touches[i].x == kGSHandInfoTypeTouchDown || touches[i].x == kGSHandInfoTypeTouchDragged || touches[i].x == kGSHandInfoTypeTouchMoved) ? 0x03 : 0x00;;
        event->handInfo.pathInfos[i].pathLocation  = CGPointMake(touches[i].x, touches[i].y);
    }

    mach_port_t port = (mach_port_t)getFrontMostAppPort();
    GSSendEvent((GSEventRecord *)event, port);

}

int test()
{
    // simulate two fingers touch from  the center to two sides of the screen.

    struct touch touchesDown[2] = [{0, 140, 200, kGSHandInfoTypeTouchDown},
                                   {1, 160, 200, kGSHandInfoTypeTouchDown}];

    struct touch touchesMove[2] = [{0, 40, 200, kGSHandInfoTypeTouchDragged},
                                   {1, 300, 200, kGSHandInfoTypeTouchDragged}];

    struct touch touchesUp[2] = [{0, 40, 200, kGSHandInfoTypeTouchUp},
                                 {1, 300, 200, kGSHandInfoTypeTouchUp}];

    sendTouches(touchesDown);
    usleep(20000);
    sendTouches(touchesMove);
    usleep(20000);
    sendTouches(touchesUp);
}
4

0 回答 0