Send a global touch event on iOS 6

六月ゝ 毕业季﹏ 提交于 2019-12-11 02:38:17

问题


I wanna build a automatic iOS app test framework. I can record the touch event by IOHIDFamily, so any way to replay this?

I tried GSEvent like this

void sendclickevent(){     
    mach_port_t thePortOfApp = GSCopyPurpleNamedPort("com.fuckyou.fuck");     

    GSEventRecord header;     
    GSHandInfo click;     
    GSPathInfo pathInfo = {2,2,2,1,1,{50,50}, NULL};     

    bzero(&header, sizeof(header));     
    bzero(&click, sizeof(click));     

    header.type = kGSEventHand;     
    header.subtype = kGSEventSubTypeUnknown;     
    header.location.x = 50;     
    header.location.y = 50;     
    header.windowLocation.x = 50;     
    header.windowLocation.y = 50;     
    header.infoSize = sizeof(GSHandInfo)+sizeof(GSPathInfo);     
    header.timestamp = mach_absolute_time();     

    click.type = kGSHandInfoTypeTouchDown;     
    click.deltaX = 1;     
    click.deltaY = 1;     
    click.pathInfosCount = 1;     

    struct    
    {     
        GSEventRecord record;     
        GSHandInfo hand;     
        GSPathInfo path;     
    } record = {header, click, pathInfo};     

    GSSendEvent(&record, thePortOfApp);     
}

thePortOfApp return Non-Zero. But at end of this function, such as press a button, nothing happpend. So something wrong? or I need another way to send touch event to iOS UI?


回答1:


Take a look some other questions related to sending events outside of your app:

Use GSEvent to send touch event,but it's invalid

Using GraphicsServices.h/GSEvent as well as compiling CLI iPhone tools with Xcode

How to send a touch event to iPhone OS?

Simulating System Wide Touch Events on iOS

Notes

1) I believe you should send touchDown first and touchUp second to get a click.

2) Most of code which I saw on this subject used GSGetPurpleSystemAppPort() which allows to send system wide events (vs GSCopyPurpleNamedPort).

I believe GSCopyPurpleNamedPort just does usual bootstrap_look_up port. So, it will find a port, even if it's no a purple port (which is most likely true for "com.fuckyou.fuck")



来源:https://stackoverflow.com/questions/15701155/send-a-global-touch-event-on-ios-6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!