I am developing a custom textfield in Cocoa. To handle the backspace character 
I should be defining :

- (void) keyUp: (NSEvent*)theEvent {
    [self interpretKeyEvents: [NSArray arrayWithObject: theEvent];

    NSString *text = [theEvent charactersIgnoringModifiers];
    [[self text] appendString: text];
}
Then implement :

- (void) deleteBackward:(id)sender {
    if ([[self text] length] == 0)
        return;
    NSString* textMinusLastCharacter = [[self text] substringToIndex: [[self 
text] length] - 1];
    [self setText: [NSMutableString stringWithString: textMinusLastCharacter]];
    [self setNeedsDisplay:YES];
}
When I run the application, for every alphanumeric character key I press I hear 
a sound. When I press the backspace key, a call is made to the deleteBackward: 
and after that the key up method appends the backspace char to the end of the 
string. How do I filter the backspace key press in a device independent manner 
(without key codes).

Seems like the event is being passed to someplace else up in the responder 
chain. How do I control that? I am avoiding comparing keyCodes that come 
through the event object. I want to remove the sound played when each character 
is pressed.


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to