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];
}
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
{
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];
}