Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you detect a ctrl-click (context menu) request in the mouseDown event?

In my cross-platform architecture, I would like to act on a context menu click (right button click) during a mouse click event. In Cocoa, can you detect that the user either Ctrl-Clicked or double-tapped on touchpad (right-click equivalent) DURING the mouseDown event? I am aware of NSView's menuForEvent but do not wish to handle it here.

like image 491
AlanKley Avatar asked Oct 22 '08 22:10

AlanKley


2 Answers

In general, -rightMouseDown: should get called automatically, but I've seen situations where it isn't -- these may be patched in Leopard.

But right now, in -mouseDown: I check whether the control key is down, using this code:

- (void)mouseDown:(NSEvent *)event;
{
    if (event.modifierFlags & NSControlKeyMask)
        return [self rightMouseDown:event];

...
}

-Wil

like image 150
Wil Shipley Avatar answered Oct 21 '22 04:10

Wil Shipley


If you're using AppKit, and you want to detect a right-click in your view, you should override -[NSResponder rightMouseDown:].

like image 32
Ben Gottlieb Avatar answered Oct 21 '22 04:10

Ben Gottlieb