HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了GSSendEvent – 注入触摸事件iOS大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在iPhone中注入触摸事件.我通过网络套接获取触摸事件的坐标. GSSendEvent似乎是不错的选择.但是,它需要GSEventRecord作为输入之一.

有谁知道如何准备GSEventRecord?我根据一些例子准备了它,但是在GSSendEvent调用之后应用程序崩溃了.

感谢任何帮助.

-(void) handleMouseEventAtPoint:(CGPoint) point
{
static mach_port_t port_;

// structure of touch GSEvent
struct GSTouchEvent {
    GSEventRecord record;
    GSHandInfo    handInfo;
} ;

struct GSTouchEvent *touchEvent = (struct GSTouchEvent *) malloc(sizeof(struct GSTouchEvent));

bzero(touchEvent,sizeof(touchEvent));

// set up GSEvent
touchEvent->record.type = kGSEventHand;
touchEvent->record.windowLOCATIOn = point;
touchEvent->record.timestamp = GSCurrentEventtimestamp();
touchEvent->record.infoSize = sizeof(GSHandInfo) + sizeof(GSPathInfo);
touchEvent->handInfo.type = getHandInfoType(0,1);
touchEvent->handInfo.pathInfosCount = 1;
bzero(&touchEvent->handInfo.pathInfos[0],sizeof(GSPathInfo));
touchEvent->handInfo.pathInfos[0].pathIndex     = 1;
touchEvent->handInfo.pathInfos[0].pathIdentity  = 2;
touchEvent->handInfo.pathInfos[0].pathProximity = 1 ? 0x03 : 0x00;
touchEvent->handInfo.pathInfos[0].pathLOCATIOn  = point;

port_ = GSGetPurpleSystemEventPort();

GSSendEvent((GSEventRecord*)touchEvent,port_);


}
static GSHandInfoType getHandInfoType(int touch_before,int touch_Now){
if (!touch_beforE) {
    return (GSHandInfoTypE) kGSHandInfoType2TouchDown;
}
if (touch_Now) {
    return (GSHandInfoTypE) kGSHandInfoType2TouchChange;
}
return (GSHandInfoTypE) kGSHandInfoType2TouchFinal;
}

解决方法

仅在iOS 6上测试过

你实际上是在正确的轨道上.问题是您必须弄清楚应该为这些变量分配的值.

首先,您需要导入Graphicsservices.h.然后,您可以使用从How to find the purple port for the front most application in IOS 5 and above?获得的端口尝试以下代码.

我不是iOS专家,Apple也没有提供任何文档,所以我无法解释这里发生了什么. (它恰好适合我.)

无论如何,你可以使用Xcode调试模式来玩它,看看幕后发生了什么.

struct GSTouchEvent * touchEvent = (struct GSTouchEvent*) &gsTouchEvent;
bzero(touchEvent,sizeof(touchEvent));
touchEvent->record.type = kGSEventHand;
touchEvent->record.subtype = kGSEventSubTypeUnkNown;
touchEvent->record.LOCATIOn = point;
touchEvent->record.windowLOCATIOn = point;
touchEvent->record.infoSize = sizeof(GSHandInfo) + sizeof(GSPathInfo);
touchEvent->record.timestamp = GSCurrentEventtimestamp();
touchEvent->record.window = winRef;
touchEvent->record.senderPID = 919;
bzero(&touchEvent->handInfo,sizeof(GSHandInfo));
bzero(&touchEvent->handInfo.pathInfos[0],sizeof(GSPathInfo));
GSHandInfo touchEventHandInfo;
touchEventHandInfo._0x5C = 0;
touchEventHandInfo.deltaX = 0;
touchEventHandInfo.deltaY = 0;
touchEventHandInfo.height = 0;
touchEventHandInfo.width = 0;
touchEvent->handInfo = touchEventHandInfo;
touchEvent->handInfo.type = handInfoType;
touchEvent->handInfo.deltaX = 1;
touchEvent->handInfo.deltaY = 1;
touchEvent->handInfo.pathInfosCount = 0;
touchEvent->handInfo.pathInfos[0].pathIndex = 1;
touchEvent->handInfo.pathInfos[0].pathIdentity = 2;
touchEvent->handInfo.pathInfos[0].pathProximity = (handInfoType == kGSHandInfoTypeTouchDown || handInfoType == kGSHandInfoTypeTouchDragged || handInfoType == kGSHandInfoTypeTouchMoved) ? 0x03: 0x00;
touchEvent->handInfo.x52 = 1;
touchEvent->handInfo.pathInfos[0].pathLOCATIOn = point;
touchEvent->handInfo.pathInfos[0].pathWindow = winRef;
GSEventRecord* record = (GSEventRecord*) touchEvent;
record->timestamp = GSCurrentEventtimestamp();
GSSendEvent(record,port);

要使用此代码,您必须多次调用它.对于一个水龙头,有触摸,触摸拖动,然后触摸.

另请注意,触摸启动时pathProximity为0.

据我记忆,winRef并不重要.

希望这可以帮助.

编辑:从Bugivore的评论来看,问题是:

大佬总结

以上是大佬教程为你收集整理的GSSendEvent – 注入触摸事件iOS全部内容,希望文章能够帮你解决GSSendEvent – 注入触摸事件iOS所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。