本文介绍了GSSendEvent - 注入触摸事件的iOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在iPhone注入触摸事件。我经由网络套接字获得触摸事件的坐标。 GSSendEvent似乎是不错的选择。然而,它需要GSEventRecord作为一个输入。

有谁知道如何prepare GSEventRecord?我prepared它基于一些例子,但GSSendEvent调用后的应用程序崩溃。

鸭preciate任何帮助。

   - (无效)handleMouseEventAtPoint:(CGPoint)点
{
静态mach_port_t port_;//触控结构GSEvent
结构GSTouchEvent {
    GSEventRecord记录;
    GSHandInfo handInfo;
};结构GSTouchEvent *的TouchEvent =(结构GSTouchEvent *)malloc的(的sizeof(结构GSTouchEvent));bzero(的TouchEvent,sizeof的(的TouchEvent));//设置GSEvent
touchEvent-> record.type = kGSEventHand;
touchEvent-> record.windowLocation =点;
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? ×03:0×00;
touchEvent-> handInfo.pathInfos [0] = .pathLocation点;port_ = GSGetPurpleSystemEventPort();GSSendEvent((GSEventRecord *)的TouchEvent,port_);
}
静态GSHandInfoType getHandInfoType(INT touch_before,诠释touch_now){
如果(!touch_before){
    返回(GSHandInfoType)kGSHandInfoType2TouchDown;
}
如果(touch_now){
    返回(GSHandInfoType)kGSHandInfoType2TouchChange;
}
返回(GSHandInfoType)kGSHandInfoType2TouchFinal;
}


解决方案

仅在iOS 6测试

您实际上是在正确的轨道上。问题是你要搞清楚什么值,你应该分配给这些变量。

首先,您需要导入GraphicsServices.h。然后,你可以尝试用端口的以下code,你可以从How寻找紫端口前大多数应用在iOS 5及以上?。

我不是专家的iOS和苹果没有提供任何文件,所以我不能解释很多东西是怎么回事。 (它发生在我很好地工作。)

无论如何,你可以用它使用X code调试模式看引擎盖下会发生什么发挥。

 结构GSTouchEvent *的TouchEvent =(结构GSTouchEvent *)及gsTouchEvent;
bzero(的TouchEvent,sizeof的(的TouchEvent));
touchEvent-> record.type = kGSEventHand;
touchEvent-> record.subtype = kGSEventSubTypeUnknown;
touchEvent-> record.location =点;
touchEvent-> record.windowLocation =点;
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)? ×03:0×00;
touchEvent-> handInfo.x52 = 1;
touchEvent-> handInfo.pathInfos [0] = .pathLocation点;
touchEvent-> handInfo.pathInfos [0] .pathWindow = winRef;
GSEventRecord *记录=(GSEventRecord *)的TouchEvent;
录音>时间戳= GSCurrentEventTimestamp();
GSSendEvent(记录,口);

要使用code,你必须调用它多次。对于一个水龙头,有向下触摸,触摸拖动,然后触摸起来。

另外请注意,pathProximity为0时,触摸到了。

据我记得,在winRef无所谓。

希望这有助于。

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

这篇关于GSSendEvent - 注入触摸事件的iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 08:03