Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Binju

macrumors member
Original poster
Jan 31, 2010
65
0
Code:
- (void) keyDown:(NSEvent *)theEvent
{
}

is not responding.Can anyone tell me the reason?
 
Code:
- (void) keyDown:(NSEvent *)theEvent
{
}

is not responding.Can anyone tell me the reason?

I wrote the method

Code:
- (void) readBinjusMind (NSEvent *) theEvent
{
}
but it is not responding.

Your method will (a) not react to the keyDown event in any way and (b) prevent it from being passed to the next responder. Where exactly did you add this method? How do you know that it is "not responding"? What did you expect to happen in which situation?
 
Code:
- (void)keyDown:(NSEvent *)event

{

 NSLog(@"Key down");

}

The above code should respond to me by giving "Key down" message when pressing any key in my keyboard know?

But it does not display the message when pressing the key.
 
It seems likely you haven't also added the following:

Code:
-(BOOL)acceptsFirstResponder
{
    [[self window] makeFirstResponder:self];
    return YES;
}
 
Code:
//  KitplayerAppDelegate.m
#import "KitplayerAppDelegate.h"
#import "QTKit/QTKit.h"
#import "QuickTime/Movies.h"
#import "Appkit/NSResponder.h"


@implementation KitplayerAppDelegate

@synthesize window;



static const unichar kESCKey = 27; 
-(BOOL)acceptsFirstResponder
{
	NSLog(@"First responder");
	 [[mMovieView window] makeFirstResponder:mMovieView];
    return YES;
}

- (void)keyDown:(NSEvent *)event
{
    NSLog(@"key down");
	unichar keyPressed = [[event charactersIgnoringModifiers] characterAtIndex:0];
	
    if( keyPressed == kESCKey )
	{
		
		
		if( [mMovieView isInFullScreenMode] )
		{
			[mMovieView exitFullScreenModeWithOptions:fullScreenOptions];
		} 
		
		
	} 

}


I placed a quick time movie view (mMovieView)in my window. While the movie is playing in full screen mode, I want to exit the fullscreen mode by pressing esc key .
 
I placed a quick time movie view (mMovieView)in my window. While the movie is playing in full screen mode, I want to exit the fullscreen mode by pressing esc key .

Thanks for finally answering the very first question that I asked. Listen, when people ask you questions, they do it for a reason. Here, your answer means I don't have to read your mind, because the problem is obvious:

You added code so that your application delegate could become first responder if it is asked to be one, and code so that your application delegate would stop a running movie when it processes an escape key. The problem is that your application delegate will _never_ be asked to become first responder, because views can become first responder, not applications, and it will _never_ be asked to process a key because the actual first responder will handle the key first.

If you want your movie view to have the ability to stop a movie playing, that's the job of the movie view. Add code there.
 
I believe that is not strictly true. If you look at NSView, it has no methods for interacting with the NSEvent, the event methods derive from NSView's first superclass, NSResponder. Hence, I believe it could be possible to make the Application delegate handle keystrokes simply by making it a subclass of NSResponder.

Try changing the line in the interface file to
Code:
@interface KitplayerAppDelegate : [COLOR="Blue"]NSResponder[/COLOR] { ...

It is not really proper Cocoa form to do that, but I think it would work. If your application might have more than one window open, however, it would be better to subclass the movie view.
 
Now, as I read his posting history, he'll not acknowledge the assistance provided, but will start another thread shortly with another problem.
 
I believe that is not strictly true. If you look at NSView, it has no methods for interacting with the NSEvent, the event methods derive from NSView's first superclass, NSResponder. Hence, I believe it could be possible to make the Application delegate handle keystrokes simply by making it a subclass of NSResponder.

Try changing the line in the interface file to
Code:
@interface KitplayerAppDelegate : [COLOR="Blue"]NSResponder[/COLOR] { ...

It is not really proper Cocoa form to do that, but I think it would work. If your application might have more than one window open, however, it would be better to subclass the movie view.

try
 
I believe that is not strictly true. If you look at NSView, it has no methods for interacting with the NSEvent, the event methods derive from NSView's first superclass, NSResponder. Hence, I believe it could be possible to make the Application delegate handle keystrokes simply by making it a subclass of NSResponder.

Try changing the line in the interface file to
Code:
@interface KitplayerAppDelegate : [COLOR="Blue"]NSResponder[/COLOR] { ...

It is not really proper Cocoa form to do that, but I think it would work. If your application might have more than one window open, however, it would be better to subclass the movie view.

No luck ya
 
No luck ya

Whilst the above is true: any NSResponder can handle NSEvents this only works if the NSResponder is in the responder chain. By default views tend to get added to the responder chain when they are in a window that is key. I'm fairly sure that this is not true of the application delegate.

You may need to add your NSResponder sub-class to the responder chain.

I would read Event Architecture (specifically the The Path of Key Events).

Note that NSApplication is a NSResponder. If you want to insert your delegate as the first object that gets to handle events then something like the below will work (say in the init of your delegate):

Code:
NSResponder *currentNextResponder  = [NSApp nextResponder];
[NSApp setNextResponder:self];
[self setNextResponder:currentNextResponder];
 
Code:
-(id) init {
    self = [super init];
	
    if ( self ) {
		NSResponder *currentNextResponder  = [NSApp nextResponder];
		[NSApp setNextResponder:self];
		[self setNextResponder:currentNextResponder];  //Got error in this line 
    
	}
	
    return self;
}
 
I didn't bother re-reading this thread, but ...

I don't believe your application delegate inherits the NSResponder protocol thus the error, or warning (depending on flag to the compiler).
 
I didn't bother re-reading this thread, but ...

I don't believe your application delegate inherits the NSResponder protocol thus the error, or warning (depending on flag to the compiler).

This is probably true. But it clearly should when key events are being captured.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.