title: Mouse callback event flags in Python/OpenCV/OSX?
body: <p>I'm using OpenCV in Python on OS X (10.10.5). I'm just starting out, so I may have made a silly mistake here. However, I haven't found anything that addresses this issue.</p>
  <p>I have a mouse callback function that makes a list containing the coordinates of each point that is clicked on in a loaded image.</p>
  <p>Now I'd like to use the flags in the mouse callback function to control whether I append coordinates to the list or whether I instead append <code>('NA', 'NA')</code>. For example, if a point is missing from an image, I could hold the <kbd>shift</kbd> key and click on the image, and a placeholder would be appended instead of coordinates.</p>
  <p>Although the <code>event</code> part of the mouse callback works*, the <code>flags</code> information doesn't seem to be available.</p>
  <p>Here's the mouse callback function:</p>
  <pre><code>img_points = []
  
  def write_points(event, x, y, flags, param):
      global img_points
      if event == cv2.EVENT_LBUTTONDOWN and flags != cv2.EVENT_FLAG_SHIFTKEY:
          img_points.append((x,y))
          print img_points
      elif event == cv2.EVENT_LBUTTONDOWN and flags == cv2.EVENT_FLAG_SHIFTKEY:
          img_points.append(('NA','NA'))
          print img_points
  </code></pre>
  <p>I've tried different versions of this, and as far as I can tell the problem is that the <code>EVENT_FLAG_SHIFTKEY</code> (or any other <code>EVENT_FLAG_*</code> information) isn't available to the function.</p>
  <p>Here's what happens if I alter the code in different ways:</p>
  <ul>
  <li><p>I don't include anything about flags, the coordinates of every point that is clicked on are appended to <code>img_points</code>, so the event part seems to be ok.</p>
  </li>
  <li><p>If I use the function as written above, the coordinates of every point that is clicked on (regardless of whether the shift key is pressed) are appended. So <code>flags != cv2.EVENT_FLAG_SHIFTKEY</code> must always be true.</p>
  </li>
  <li><p>If I use the code as written above, but replace <code>flags != cv2.EVENT_FLAG_SHIFTKEY</code> with, say, <code>flags == cv2.EVENT_FLAG_CTRLKEY</code>, then nothing happens when I click regardless of whether I'm holding any buttons. That would suggest that regardless of what I do with the keyboard, <code>flags == cv2.EVENT_FLAG_CTRLKEY</code> and <code>flags == cv2.EVENT_FLAG_SHIFTKEY</code> are both always false.</p>
  </li>
  </ul>
  <p>Any ideas what is wrong here? Am I using event flags incorrectly? Is it a problem with the way OS X encodes keys/right clicks? How can I fix it?</p>
  <hr />
  <p><sup>*</sup> Additional note: actually, the event <code>EVENT_LBUTTONDOWN</code> is the only event that works. Similar to this post, <a href="https://stackoverflow.com/questions/5000721/mouse-event-handling-with-cvsetmousecallback">Mouse event handling with cvSetMouseCallback</a>, <code>EVENT_RBUTTONDOWN</code> and the double click events don't work (a double click registers as two clicks and appends two sets of coordinates). I've tried this both with the trackpad and with an external mouse (the answer to the other post didn't solve the issue).</p>