[英]Is it possible to simulate click using CGEvent for iOS app on Mac with M1?
I am trying to send click event to iOS-base app from App Store on ARM Mac(Apple Silicone, M1).我正在尝试从 ARM Mac(Apple Silicone,M1)上的 App Store 向基于 iOS 的应用程序发送点击事件。
Here is snippet that works for any non-ios app:这是适用于任何非 ios 应用程序的代码段:
import Foundation
func testClick(){
let source = CGEventSource.init(stateID: .hidSystemState)
let position = CGPoint(x: 100, y: 100)
let eventDown = CGEvent(mouseEventSource: source, mouseType: .leftMouseDown, mouseCursorPosition: position , mouseButton: .left)
let eventUp = CGEvent(mouseEventSource: source, mouseType: .leftMouseUp, mouseCursorPosition: position , mouseButton: .left)
eventDown?.post(tap: .cghidEventTap)
usleep(500_000)
eventUp?.post(tap: .cghidEventTap)
}
With any iOS-app this code will move cursor, but won't simulate click.对于任何 iOS 应用,此代码将移动 cursor,但不会模拟点击。
After the last Big Sur update this code works, but you need to focus window first time.在上次 Big Sur 更新后,此代码有效,但您需要第一次关注 window。
if(firstTime) testClick()
testClick()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.