GSSendEvent – 注入触摸事件iOS

GSSendEvent – 注入触摸事件iOS,第1张

概述我想在iPhone中注入触摸事件.我通过网络套接字获取触摸事件的坐标. GSSendEvent似乎是不错的选择.但是,它需要GSEventRecord作为输入之一. 有谁知道如何准备GSEventRecord?我根据一些例子准备了它,但是在GSSendEvent调用之后应用程序崩溃了. 感谢任何帮助. -(void) handleMouseEventAtPoint:(CGPoint) point 我想在iPhone中注入触摸事件.我通过网络套接字获取触摸事件的坐标. GSSendEvent似乎是不错的选择.但是,它需要GSEventRecord作为输入之一.

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

感谢任何帮助.

-(voID) handleMouseEventAtPoint:(CGPoint) point{static mach_port_t port_;// structure of touch GSEventstruct GStouchEvent {    GSEventRecord record;    GSHandInfo    handInfo;} ;struct GStouchEvent *touchEvent = (struct GStouchEvent *) malloc(sizeof(struct GStouchEvent));bzero(touchEvent,sizeof(touchEvent));// set up GSEventtouchEvent->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的评论来看,问题是:

The way I allocated touchEvent via malloc was wrong. It should be done as EntryLevelDev showed – “static uint8_t handJob[sizeof(GSEventRecord) + sizeof(GSHandInfo) + sizeof(GSPathInfo)];”

总结

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

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

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1104255.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存