Home > Software design >  How to differentiate side and wheel buttons with cocoa?
How to differentiate side and wheel buttons with cocoa?

Time:09-16

I have mouse with 5 buttons. They are left, right, wheel and 2 side buttons (back/forward). Is there any way to check, whether side button ("back" for example) was pressed? I learning cocoa's documentation about mouse event. At the moment I know that there is - (void)otherMouseDown:(NSEvent *)event; method, which is called whenever other (not right/left) button was pressed. But documentation tells nothing about additional information about which button was actually pressed. How to overcome this?

CodePudding user response:

-(void)scrollWheel:(NSEvent *)event; method of NSResponder and so also from NSViews

- (void)rightMouseDown:(NSEvent *)event; same way

- (void)otherMouseDown:(NSEvent *)event as you know

but also..

-(void)someAction:(id)sender 
{
    NSEvent *event = [NSApp currentEvent];
    if (event.type == NSEventTypeLeftMouseUp ||
        event.type == NSEventTypeLeftMouseDown) 
    { 
        if (event.clickCount == 2) {  
            // doubleClick
        }
    } 
    else if (event.type == NSEventTypeOtherMouseDown) 
    {
        if (event.buttonNumber==4) 
        {
            //i think first button is 0, so 5 should be 4.
        }
    }
}

AppKit's NSEvent.h has everything you need just check the type of the event first and then go for buttonNumber and what ever you choose

  • Related