简体   繁体   English

是否可以在带有 M1 的 Mac 上使用 CGEvent 模拟 iOS 应用程序的点击?

[英]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.

相关问题 如何模拟从Mac App到其他应用程序的鼠标单击 - How to simulate mouse click from Mac App to other Application Mac M1获取IOMobileFramebufferUserClient接口 - Mac M1 get IOMobileFramebufferUserClient interface React Native 设置 Mac M1 (Air) - React Native setup Mac M1 (Air) 为什么我的 M1 Mac 上的 Xcode 试图为 `iOS Simulator-x86_64` 构建? 为什么它不是为基于“arm”的模拟器构建的? - Why is Xcode on my M1 Mac trying to build for `iOS Simulator-x86_64`? Why is it not building for an `arm` based simulator? iOS 模拟器在具有二进制框架的 M1 Mac 上构建失败 - “Swift 5.5.1 编译器无法导入使用 Swift 5.4.2 编译的模块” - iOS simulator builds fail on M1 Mac with binary framework - "Module compiled with Swift 5.4.2 cannot be imported by the Swift 5.5.1 compiler" Google Places、Swift Package Manager 和 M1 Mac 问题 - Google Places, Swift Package Manager & M1 Mac issues 为 M1 Mac 构建项目失败,因为它认为缺少架构 - Building project for M1 Mac fails because of architectures it believes are missing 如果不使用 rosseta,我无法使用 Apple Silicon m1 Pro 构建我的应用程序 - I can't build my app with apple silicon m1 pro without using rosseta 打开 CV:为 Mac M1 编译时未定义 cv::LineIterator - Open CV: cv::LineIterator undefined when compiling for Mac M1 共享 Web 凭证功能在 M1 Mac 上不起作用 - Shared Web Credentials Feature is not worked on M1 Mac
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM