-->

使用GSEvent发送触摸事件,但它是无效的(Use GSEvent to send touch e

2019-09-16 16:45发布

我的代码由GSCopyPurpleSystemEventPort触摸事件由GSEvent发送到我的应用程序,让mach_port_t()。

发送功能得到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!");
    }
}

但对越狱的ipad2(iOS5.01)的应用程序启动,没有任何点击的结果,如果点击事件完成后,将的debug.log在那里。

谁可以告诉我,我有什么小姐?

Answer 1:

我已经看到了这个代码在其他地方(我认为这是对一个应用程序,翻译鼠标点击到iPhone / iPad的水龙头)。 这里的问题是不是代码或端口,但是您发送的事件结构。 这是GSevent结构为iOS 3.0,而不是为iOS 5.0。 它改变了,不仅在结构,但在价值观和标签。 我建议接收UIEvents,将它们转换为GSEvents,看着他们的内容。



文章来源: Use GSEvent to send touch event,but it's invalid