Iphone 使用GSEvent发送触摸事件,但它';那是无效的

Iphone 使用GSEvent发送触摸事件,但它';那是无效的,iphone,ios,iphone-privateapi,Iphone,Ios,Iphone Privateapi,我编写代码通过GSEvent向我的应用程序发送触摸事件,通过GSCopyPurpleSystemEventPort()获取mach_端口 发送功能在ApplicationIDFinishLaunch:选项完成后启动。该应用程序为uicontrol查看应用程序 代码如下: void handleMouseEventAtPoint(CGPoint point, int buttons) { // NOTE: Must store button state for comparision, p

我编写代码通过GSEvent向我的应用程序发送触摸事件,通过GSCopyPurpleSystemEventPort()获取mach_端口

发送功能在ApplicationIDFinishLaunch:选项完成后启动。该应用程序为uicontrol查看应用程序

代码如下:

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!");
    }
}
但是在越狱ipad2(iOS5.01)上启动应用程序时,没有任何单击结果,如果单击事件完成,debug.log就会出现


谁能告诉我我错过了什么?

我在其他地方见过这段代码(我想它是在一个将鼠标点击转换为iPhone/iPad点击的应用程序上)。这里的问题不是代码或端口,而是发送的事件结构。这是iOS 3.0的GSevent结构,而不是iOS 5.0。它不仅在结构上,而且在值和标记上都发生了变化。我建议接收UIEvents,将其翻译成GSEvents并查看其内容。

是否有关于iOS 5.0在线版GSEvent结构的信息?如果有,请提供URL?否,在线版没有。您最多只能访问KennyTM的私有API库。我建议您接收每个UIEvent并将其转换为GSEvent。然后仔细查看您收到的值,制作一个类似的结构并发送。我覆盖touchesbeated:withEvent:,并将其转换为GSEvent to force,查看结构,但我认为此信息是错误的。可能无法将其转换为GSEvent to force。如何将其转换为UIEvent?您应该使用实例方法-(GSEventRef)\u gsEvent;然后将其转换为GSEventRecord,然后查看值。我按照您所说的进行转换,我发现属性值与GSEvent相同。h.它仍然是不可更改的。您还有其他建议吗。我想见鬼去吧。这方面有进一步的进展吗?您是否能够为ios 5.0以后的版本发送触摸事件?如果是,请让我们也知道。