<p>In response to a rightMouse event I want to call a function that displays a context menu, runs it, and responds to the selected menu item.  In Windows I can use TrackPopupMenu with the TPM_RETURNCMD flag.</p>

<p>What is the easiest way to implement this in Cocoa?  It seems NSMenu:popUpContextMenu wants to post an event to the specified NSView.  Must I create a dummy view and wait for the event before returning?  If so, how do I "wait" or flush events given I am not returning to my main ?</p>

The 'proper' way to do this in Cocoa is to have your menu item's target and action perform the required method. However, if you must do it within your initial call, you can use
```
[NSView nextEventMatchingMask:]
```
to continually fetch new events that interest you, handle them, and loop. Here's an example which just waits until the right mouse button is released. You'll probably want to use a more complex mask argument, and continually call
```
[NSView nextEventMatchingMask:]
```
until you get what you want.
```
```
NSEvent *localEvent = [[self window] nextEventMatchingMask: NSRightMouseUpMask];
```
```
I think you'll find the 'proper' way to go much easier.