Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Multiple keyDown: keyUp: s

Multiple keyDown: keyUp: s
Thread Tools
Xtraz
Forum Regular
Join Date: May 2000
Status: Offline
Reply With Quote
Mar 6, 2004, 07:19 PM
 
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];
}
     
Xtraz  (op)
Forum Regular
Join Date: May 2000
Status: Offline
Reply With Quote
Mar 10, 2004, 12:48 AM
 
Can't anyone offer me just a little advice or a hint?
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Mar 10, 2004, 05:02 AM
 
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 Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 08:45 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,