0

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.

Michel
  • 10,303
  • 17
  • 82
  • 179
  • https://stackoverflow.com/questions/31931403/getting-mouse-coordinates-in-swift/31932049?r=SearchResults&s=1|30.9261#31932049 regarding the mouse click you need to monitor the mouseDown events – Leo Dabus Aug 01 '19 at 05:31
  • I have indeed already found NSEvent.mouseEvent(...) But did not really see any anything clear on how to make use of that. I am not sure this is what you are referring to though. – Michel Aug 01 '19 at 11:04

0 Answers0