ios - 在 iOS 6 上发送全局触摸事件
<p><p>我想构建一个自动 iOS 应用测试框架。我可以通过 IOHIDFamily 记录触摸事件,那么有什么方法可以重播呢?</p>
<p>我试过这样的 GSEvent</p>
<pre><code>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);
}
</code></pre>
<p>thePortOfApp 返回非零值。但是在这个功能结束时,比如按下一个按钮,什么都没有发生。那么有什么问题吗?或者我需要另一种方式将触摸事件发送到 iOS UI?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>查看与在应用外发送事件相关的其他一些问题:</p>
<p> <a href="https://stackoverflow.com/questions/10274405/use-gsevent-to-send-touch-event-but-its-inviald" rel="noreferrer noopener nofollow">Use GSEvent to send touch event,but it's invalid</a> </p>
<p> <a href="https://stackoverflow.com/questions/3017367/using-graphicsservices-h-gsevent-as-well-as-compiling-cli-iphone-tools-with-xcod" rel="noreferrer noopener nofollow">Using GraphicsServices.h/GSEvent as well as compiling CLI iPhone tools with Xcode</a> </p>
<p> <a href="https://stackoverflow.com/questions/1746452/how-to-send-a-touch-event-to-iphone-os/10515571#10515571" rel="noreferrer noopener nofollow">How to send a touch event to iPhone OS?</a> </p>
<p> <a href="https://stackoverflow.com/questions/9221086/simulating-system-wide-touch-events-on-ios/9988262#9988262" rel="noreferrer noopener nofollow">Simulating System Wide Touch Events on iOS</a> </p>
<p><strong>备注</strong></p>
<p>1) 我认为您应该先发送 touchDown 然后再发送 touchUp 以获得点击。</p>
<p>2) 我在这个主题上看到的大部分代码都使用了 GSGetPurpleSystemAppPort(),它允许发送系统范围的事件(与 GSCopyPurpleNamedPort 相比)。</p>
<p>我相信 GSCopyPurpleNamedPort 只是做通常的 bootstrap_look_up 端口。所以,它会找到一个端口,即使它不是紫色端口(对于“com.fuckyou.fuck”来说很可能是这样)</p></p>
<p style="font-size: 20px;">关于ios - 在 iOS 6 上发送全局触摸事件,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/15701155/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/15701155/
</a>
</p>
页:
[1]