objective-cnsresponder

Is there a KeyUp: method for flagsChanged:?


I have implemented the - (void)flagsChanged:(NSEvent *)theEvent method in my application. It works fine when I hold down the [alt] key. The method only sends when the key is pressed, but not when I let it go again. The - (void)keyUp:(NSEvent *)theEvent won't be called. Is there anyway to see when the [alt] key is released?

Here is the code:

- (void)flagsChanged:(NSEvent *)theEvent
{
    if([theEvent modifierFlags] & NSAlternateKeyMask)
    {
        NSLog(@"alt is down!!!");
    }
}

Solution

  • Okay. I really need to test the code a bit more. After logging the NSEvent, I noticed that the keyUp method is already implemented (thanks Jonathan Grynspan for pointing it out in the comment).

    So now my code is:

    - (void)flagsChanged:(NSEvent *)theEvent
    {
        if([theEvent modifierFlags] & NSAlternateKeyMask)
        {
            NSLog(@"alt is down!!!");
        }
        else if([theEvent keyCode] == 58)
        {
            NSLog(@"alt is up!!!");
        }
    }
    

    This now works fine!