So basically I’m making an auto clicker for Mac in Xcode 16.0, but the CGEvent doesn’t seem to work. I searched the internet and viewed documentation, but I couldn’t find much about it. Here’s my code
let source = CGEventSource(stateID: .hidSystemState)
let mouseLocation = NSEvent.mouseLocation
CGEvent.init(mouseEventSource: source, mouseType: .leftMouseDown, mouseCursorPosition: mouseLocation, mouseButton: .left)?.post(tap: .cghidEventTap)
usleep(100_000)
CGEvent.init(mouseEventSource: source, mouseType: .leftMouseUp, mouseCursorPosition: mouseLocation, mouseButton: .left)?.post(tap: .cghidEventTap)
I also tried moving the mouse but nothing. I also gave it access to control my computer (in settings > privacy & security > accessibility > my app) as it is required to do everything with mouse and keyboard. But still no.
4