Question

This is to implement a keyboard based game controller. Left/Right arrows makes the character walk. shift+left/right makes the character run.

Here's the code I'm using so far:

- (void)keyDown:(NSEvent *)event{

    if ([event modifierFlags] & NSShiftKeyMask) {
        NSLog(@"Shift key pressed");
    }
    // logic follows
}

This works fine if shift is pressed before pressing an arrow key. But if an arrow key is pressed and you need to accelerate, pressing shift won't cause anything to happen...

So, I see this kind of answer: https://stackoverflow.com/a/420691/987818

But I don't understand where this NSResponder is being used. For info, I use Cocos2D (objc game engine).

thanks for any leads :-) J.

Was it helpful?

Solution

You need to implement flagsChanged: in the same class where you implement this -keyDown: method, or just any NSResponder subclass that may be able to catch this event (e.g. the NSApplication).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top