1

通过在stackoverflow中搜索,我得到了如何在iOS上模拟touchDown事件,但经过多次尝试,我没有得到如何使用GSEvent制作touchMoved事件,有人知道吗?

模拟一个 touchDown 事件:

static void sendclickevent() {

CGPoint location = CGPointMake(200, 288);

// structure of touch GSEvent
struct GSTouchEvent {
    GSEventRecord record;
    GSHandInfo    handInfo;
} * event = (struct GSTouchEvent*) &touchEvent;
bzero(touchEvent, sizeof(touchEvent));

// set up GSEvent
event->record.type = kGSEventHand;
event->record.windowLocation = location;
event->record.timestamp = GSCurrentEventTimestamp();
event->record.infoSize = sizeof(GSHandInfo) + sizeof(GSPathInfo);
event->handInfo.type = kGSHandInfoTypeTouchDown;
if (is_50_or_higher){
    event->handInfo.x52 = 1;
} else {
    event->handInfo.pathInfosCount = 1;
}
bzero(&event->handInfo.pathInfos[0], sizeof(GSPathInfo));
event->handInfo.pathInfos[0].pathIndex     = 1;
event->handInfo.pathInfos[0].pathIdentity  = 2;
event->handInfo.pathInfos[0].pathProximity = 1 ? 0x03 : 0x00;;
event->handInfo.pathInfos[0].pathLocation  = location;

mach_port_t port = (mach_port_t)getFrontMostAppPort();
GSSendEvent((GSEventRecord *)event, port);
}
4

1 回答 1

1
  event->handInfo.type = kGSHandInfoTypeTouchDown;

你有一个触地得分,你有一个触地得分,对吗?

单击一下是这样的:

   touchdownAtPoint(x,y);
   wait(0.1);//wait for 0.1 sec
   touchUpAtPoint(x,y);

当你想做一个触摸感动的时候,应该是这样的:

    touchdownAtPoint(x,y);
     touchdownAtPoint(x+1,y);//scroll to right?
    touchdownAtPoint(x+2,y);
     .................
     touchdownAtPoint(x+n,y);
     touchUpAtPoint(x+n,y);

当然,您应该为它编写自己的循环。无论如何,我不知道这是否是最正确的方法,但我让它工作了。

于 2013-08-01T09:36:04.383 回答