In a macOS app I have code like this:
DispatchQueue.global(qos: .default).async {
while true {
self.mouseLoc = NSEvent.mouseLocation
if self.mouseLoc == self.storeMouseLoc {continue}
Thread.sleep(forTimeInterval: 0.1)
self.storeMouseLoc = self.mouseLoc
// I can do lots of useful thing here .....
}
}
And it works as I want. But now I need a way to detect when a mouse button has been clicked and then do something useful with it.
How can I do that?
What I have found browsing the net doesn't seem clear at all.