Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions PlayTools/Controls/PTFakeTouch/Additions/IOHIDEvent+KIF.m
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,39 @@ IOHIDEventRef kif_IOHIDEventWithTouches(NSArray *touches) {
IOHIDEventSetIntegerValue(handEvent, kIOHIDEventFieldDigitizerIsDisplayIntegrated, true);

for (UITouch *touch in touches) {
uint32_t eventMask = (touch.phase == UITouchPhaseMoved) ? kIOHIDDigitizerEventPosition : (kIOHIDDigitizerEventRange | kIOHIDDigitizerEventTouch);
uint32_t isTouching = (touch.phase == UITouchPhaseEnded) ? 0 : 1;
// Set eventMask and touch/range state based on actual touch phase.
// These must accurately reflect the UITouch.phase so that game-side
// validation (e.g. Tencent anti-automation) does not flag the IO HID
// event as inconsistent with the UIKit touch state.
uint32_t eventMask;
uint32_t isTouching;
switch (touch.phase) {
case UITouchPhaseMoved:
eventMask = kIOHIDDigitizerEventPosition;
isTouching = 1;
break;
case UITouchPhaseEnded:
case UITouchPhaseCancelled:
eventMask = kIOHIDDigitizerEventTouch;
isTouching = 0;
break;
default: // Began / Stationary
eventMask = kIOHIDDigitizerEventRange | kIOHIDDigitizerEventTouch;
isTouching = 1;
break;
}

CGPoint touchLocation = [touch locationInView:touch.window];

// Each finger gets its own timestamp for more realistic HID events.
// Real multi-touch hardware fires independent events per finger.
uint64_t fingerTime = mach_absolute_time();
AbsoluteTime fingerTimestamp;
Comment thread
TheMoonThatRises marked this conversation as resolved.
fingerTimestamp.hi = (UInt32)(fingerTime >> 32);
fingerTimestamp.lo = (UInt32)(fingerTime);

IOHIDEventRef fingerEvent = IOHIDEventCreateDigitizerFingerEventWithQuality(kCFAllocatorDefault, // allocator
timeStamp, // timestamp
fingerTimestamp, // finger timestamp
(UInt32)[touches indexOfObject:touch] + 1, //index
2, // identity
eventMask, // eventMask
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ - (void)setPhaseAndUpdateTimestamp:(UITouchPhase)phase
//DLog(@"setPhaseAndUpdateTimestamp : %ld",(long)phase);
[self setTimestamp: [[NSProcessInfo processInfo] systemUptime]];
[self setPhase:phase];
// Update the IOHIDEvent to match the new phase.
// Some games validate IOHIDEvent.eventMask against UITouch.phase,
// so keeping them in sync is critical for fake touch acceptance.
[self kif_setHidEvent];
}

- (void)kif_setHidEvent {
Expand Down
Loading