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

claired

macrumors newbie
Original poster
Nov 4, 2008
4
0
I cannot seem to get my keyDown event to work although my view is set to accept first responder.
When any a key is pressed a beep is sounded.
If I put a breakpoint on the keyDown method, it is never reached and nothing is logged for the event in the debugger window.

I have searched this site and there was a similar problem but it looked like the developer had not set his view to accept first responder.

Please see the code in question below. Any help would be greatly appreciated.


#pragma mark EVENTS

- (BOOL)acceptsFirstResponder
{
return YES;
}

- (BOOL)becomeFirstResponder
{
return YES;
}

- (void)keyDown:(NSEvent *)theEvent
{
if ([theEvent modifierFlags] & NSNumericPadKeyMask)
{
// arrow keys have this mask
NSString *theArrow = [theEvent charactersIgnoringModifiers];
unichar keyChar = 0;

if ( [theArrow length] == 0 )return;
// reject dead keys

if ( [theArrow length] == 1 )
{
keyChar = [theArrow characterAtIndex:0];

if ( keyChar == NSLeftArrowFunctionKey )
{
[self showThePreviousImage];
return;
}
if ( keyChar == NSRightArrowFunctionKey )
{
[self showTheNextImage];
return;
}


[super keyDown:theEvent];
}
}
[super keyDown:theEvent];
}
 
Your code works fine for me. I'm not sure the issue, but make sure you don't have a subview within that view that can become first responder.
 
Thanks for getting back to me and testing out the code.

I have a window that contains an IKImageView. This is a real newbie question, but would you class that as a sub-view?
 
Sorry for the delay in reply.

Thanks again for your help.
I had a hunch that would be the answer.
Not sure what else to check/change to get the cursor keys working.
 
Feel free to post your project here, or you could PM me and I could take a look.
 
Again, sorry for taking so long to get back to you.

Thanks for your reply.
I have managed to get it to accept a key press. It was a newbie mistake!
The Window needed the class changing to use the App Controller.

Once again, thank you for all of your help.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.