簡體   English   中英

是否可以在帶有 M1 的 Mac 上使用 CGEvent 模擬 iOS 應用程序的點擊?

[英]Is it possible to simulate click using CGEvent for iOS app on Mac with M1?

我正在嘗試從 ARM Mac(Apple Silicone,M1)上的 App Store 向基於 iOS 的應用程序發送點擊事件。

這是適用於任何非 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)
}

對於任何 iOS 應用,此代碼將移動 cursor,但不會模擬點擊。

在上次 Big Sur 更新后,此代碼有效,但您需要第一次關注 window。

if(firstTime) testClick()
testClick()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM