How are multiple keys interpreted in the responder chain? Say, if I press and hold the key 1 and then press key 2 before releasing key 1, presumably there'd be two keyDown's.
Also are keyDown messages sent continually? For some reason this seems to be the case for me. I want just one message in the up-to-down transition of the key, but it seems to keep sending the message...
Background - I'm trying to implement a program where pressing down on a key would start a quicktime movie, and releasing the key would stop it. (ie. the movie would only play when the key is held down). I have a control NSPanel in which I added code to keyUp and keyDown, which calls my controller class (the delegate) to play the movies. It seems to get confused when multiple keys are being pressed.
-(void) keyDown: (NSEvent *)theEvent
{
char key = [[theEvent charactersIgnoringModifiers] characterAtIndex:0];
if(key=='1')
{
if ([[self delegate] respondsToSelector:@selector(movieOn1)])
[[self delegate] movieOn1];
}
else if(key=='2')
{
if ([[self delegate] respondsToSelector:@selector(movieOn2)])
[[self delegate] movieOn2];
}
else
[super keyDown:theEvent];
}
-(void) keyUp: (NSEvent *)theEvent
{
char key = [[theEvent charactersIgnoringModifiers] characterAtIndex:0];
if(key=='1')
{
if ([[self delegate] respondsToSelector:@selector(movieOff1)])
[[self delegate] movieOff1];
}
else if(key=='2')
{
if ([[self delegate] respondsToSelector:@selector(movieOff2)])
[[self delegate] movieOff2];
}
else
[super keyDown:theEvent];
}