Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 为什么我可以´;不执行鼠标左键单击吗?_Swift_Macos_Qmouseevent - Fatal编程技术网

Swift 为什么我可以´;不执行鼠标左键单击吗?

Swift 为什么我可以´;不执行鼠标左键单击吗?,swift,macos,qmouseevent,Swift,Macos,Qmouseevent,我正在创建一个移动鼠标光标并执行左键和右键单击的软件。我移动了光标,但无法执行左键单击。我做错了什么 let point = CGPoint(x:366, y:528) // Random point self.moveCursor(point: point) // click mouse let eventMouseDown = CGEvent(mouseEventSource: nil, mouseType: .leftMouseDown, mouse

我正在创建一个移动鼠标光标并执行左键和右键单击的软件。我移动了光标,但无法执行左键单击。我做错了什么

let point = CGPoint(x:366, y:528) // Random point
    self.moveCursor(point: point)

    // click mouse
    let eventMouseDown = CGEvent(mouseEventSource: nil, mouseType: 
      .leftMouseDown, mouseCursorPosition: point, mouseButton:.left)
    eventMouseDown?.post(tap: .cghidEventTap)

    // release mouse
    let eventMouseUp = CGEvent(mouseEventSource: nil, mouseType: 
      .leftMouseUp, mouseCursorPosition: point, mouseButton: .left)
     eventMouseUp?.post(tap: .cghidEventTap)

应用程序沙盒是否已关闭?是,但仍不工作。它应该在指定的CGPoint中执行click,但它没有。你正在运行Mojave测试版吗?不,high Sierra V.10.13.4我试过你的代码,它对我有效。我删除了self.moveCursor(点:点)。代码是否在主线程上执行?