|
|
Multiple keyDown: keyUp: s
|
|
|
|
Forum Regular
Join Date: May 2000
Status:
Offline
|
|
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];
}
|
|
|
|
|
|
|
|
|
Forum Regular
Join Date: May 2000
Status:
Offline
|
|
Can't anyone offer me just a little advice or a hint?
|
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
Originally posted by Xtraz:
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.
Yes, that's right.
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...
Key repeat is an option in System Preferences. You can test if a key event is a repeat with NSEvent's isARepeat method.
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|