Find the right mouse button on cocoa

I am trying to control mouse events in my prototype game Sprite-kit .

I used the following methods from the SO_q question

- (void) mouseDown: (NSEvent*) theEvent
{
    NSLog(@"Click!");
}

- (void) rightMouseDown:(NSEvent*) theEvent
{
    NSLog(@"DERECHA PULSADA!");
}

But the right click detection method does not work for me. I want to detect a click and a drop in a right click. How can I detect when a mouse click is dropped?

UPDATE:

I tried with the following mehod taken from Cocoa's Event Processing Documentation .

- (void)mouseDown:(NSEvent *)theEvent 
{
        switch ([theEvent type])
        {
            case NSLeftMouseDown:
                NSLog(@"ISQUIERDO down!");
                break;
            case NSLeftMouseUp:
                NSLog(@"IZQDO soltado!");
                break;
            case RightMouseDown:
                NSLog(@"DERECHO PUSSSHHH!");
                break;
            case NSRightMouseUp:
                NSLog(@"Botón Derecho Soltado!");
                break;
            default:
                /* Ignore any other kind of event. */
                break;
        }

    return;
}

Result: only the event for the left click is processed.

After reading Cocoa Event Processing Documentation, I tried to rewrite the following methods:

-(void)rightMouseDown:(NSEvent *)theEvent
{
    NSLog(@"DERECHO PUSSSHHH!");
}

- (void)rightMouseUp:(NSEvent *)theEvent
{
    NSLog(@"Botón Derecho Soltado!");
}

Doesn't work either.

UPDATE:

, Sprite-Kit. , .

#import <SpriteKit/SpriteKit.h>

@interface OpcionesMenu : SKScene

@end
+4
2

Apple NSView, , NSM : RightMouseDown: , , menuForEvent:.

SKView - NSView, , SKView rightMouseDown:. rightMouseDown: rightMouseDown:, . SKView , , . rightMouseDown :

ObjC:

@implementation SKView (Right_Mouse)
-(void)rightMouseDown:(NSEvent *)theEvent {
     [self.scene rightMouseDown:theEvent];
}
@end

, .

Swift 3 + iOS10:

extension SKView {
  open override func rightMouseDown(with theEvent: NSEvent) {
    self.scene?.rightMouseDown(with: theEvent)
  }
}

Swift:

extension SKView {
    public override func rightMouseDown(theEvent: NSEvent) {  
        self.scene?.rightMouseDown(theEvent)
    } 
}

SKScene

override func rightMouseDown(theEvent: NSEvent) {
    let location = theEvent.locationInNode(self)
    ...
}
+14
extension SKView {

public override func rightMouseDown(theEvent: NSEvent) {
    self.scene?.rightMouseDown(theEvent)
}

swift, , !

+2

All Articles