title: How can I check the position of the mouse on screen against a bitmap in the background? (Cocoa/Objective C)
body: <p>I'm looking for a method to define an area of the screen that the mouse cannot leave. I have been directed by rob mayoff, the answerer of <a href="https://stackoverflow.com/questions/8188193/limiting-mouse-to-one-display-on-mac-potentially-using-cocoa">this</a> question, that I can use a Quartz Event Tap to detect mouse events. This puts me part of the way to the solution to THIS question. </p>
  
  <p>I need to define an irregular area of the screen, not just a rectangle, that the mouse cannot leave. I have been researching this and the only idea I can come up with is using a bitmap to define the irregular area, as it will be very oddly shaped. However, I am open to solutions other than using a bitmap.</p>
  
  <p>Since this must be done on a Mac, I've determined that I will have to use objective C / Cocoa .  </p>
  
  <p>I need to know how to define the area and, equally importantly, how to find the closest point in the area to the mouse (so that I can move the mouse to it if the mouse tries to move outside of the area). </p>
  
  <p>This is similar to what the restricted area will look like:</p>
  
  <p><img src="https://i.stack.imgur.com/0W23R.png" alt="screenshot"></p>