Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7598349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:23:10+00:00 2026-05-30T22:23:10+00:00

I’d really like my custom view to work with -moveLeft: , -deleteForward: , -selectAll:

  • 0

I’d really like my custom view to work with -moveLeft:, -deleteForward:, -selectAll:, etc., but I’d also like to pass any keys I didn’t care about onward up the responder chain. Right now I’m overriding -keyDown: to call [self interpretKeyEvents:[NSArray arrayWithObject:event]];, but this seems to hog all the key events, even ones my view doesn’t respond to.

Is there any way to pass unwanted events up the chain, but still respond to -moveLeft:, etc.? Or do I need to implement all my own actions in -keyDown: so that I know what I did and did not respond to?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T22:23:11+00:00Added an answer on May 30, 2026 at 10:23 pm

    Came across this trying to find a solution to this same problem. Never found anything online, but I came up with something that seems to work well so far. Here’s what I’m doing:

    Subclass your NSTextView (or whatever you’re using) and create an instance variable to temporarily store the key down event . . .

    @interface MyTextView : NSTextView {
        NSEvent* _keyDownEvent;
    }
    
    @end
    

    Then define your view’s methods like so (take out the retain/release junk if you’re using automatic reference counting):

    @implementation MyTextView
    
    - (id)initWithFrame:(NSRect)frame {
        if (self = [super initWithFrame:frame]) {
            _keyDownEvent = nil;
        }
    
        return self;
    }
    
    - (void)keyDown:(NSEvent*)event {
        [_keyDownEvent release];
        _keyDownEvent = [event retain];
        [super keyDown:event];
    }
    
    - (void)doCommandBySelector:(SEL)selector {
        if (_keyDownEvent && selector == @selector(noop:)) {
            if ([self nextResponder]) {
                [[self nextResponder] keyDown:[_keyDownEvent autorelease]];
            } else {
                [_keyDownEvent release];
            }
            _keyDownEvent = nil;
        } else {
            [super doCommandBySelector:selector];
        }
    }
    
    - (void)dealloc {
        [_keyDownEvent release];
    
        [super dealloc];
    }
    
    @end
    

    Here’s how I arrived at this. When a key press isn’t handled, you hear a beeping tone. So, I set a breakpoint on NSBeep(), and when the program broke, I spit out a stack trace in GDB:

    #0  0x00007fff96eb1c2d in NSBeep ()
    #1  0x00007fff96e6d739 in -[NSResponder doCommandBySelector:] ()
    #2  0x00007fff96e6d72b in -[NSResponder doCommandBySelector:] ()
    #3  0x00007fff96fda826 in -[NSWindow doCommandBySelector:] ()
    #4  0x00007fff96e6d72b in -[NSResponder doCommandBySelector:] ()
    #5  0x00007fff96e6d72b in -[NSResponder doCommandBySelector:] ()
    #6  0x00007fff96e6d72b in -[NSResponder doCommandBySelector:] ()
    #7  0x00007fff96e6d72b in -[NSResponder doCommandBySelector:] ()
    #8  0x00007fff96e6d72b in -[NSResponder doCommandBySelector:] ()
    #9  0x00007fff96e6d72b in -[NSResponder doCommandBySelector:] ()
    #10 0x00007fff96e6d72b in -[NSResponder doCommandBySelector:] ()
    #11 0x00007fff96f486ce in -[NSTextView doCommandBySelector:] ()
    #12 0x00007fff96da1c93 in -[NSKeyBindingManager(NSKeyBindingManager_MultiClients) interpretEventAsCommand:forClient:] ()
    #13 0x00007fff970f5382 in -[NSTextInputContext handleEvent:] ()
    #14 0x00007fff96fbfd2a in -[NSView interpretKeyEvents:] ()
    #15 0x00007fff96f38a25 in -[NSTextView keyDown:] ()
    #16 0x0000000100012889 in -[MyTextView keyDown:] (self=0x1004763a0, _cmd=0x7fff972b0234, event=0x100197320) at /path/MyTextView.m:24
    #17 0x00007fff96a16b44 in -[NSWindow sendEvent:] ()
    #18 0x00007fff969af16d in -[NSApplication sendEvent:] ()
    #19 0x00007fff969451f2 in -[NSApplication run] ()
    #20 0x00007fff96bc3b88 in NSApplicationMain ()
    #21 0x00000001000015e2 in main (argc=3, argv=0x7fff5fbff8f0) at /path/main.m:12
    

    What’s happening is this: When the key down event isn’t used for text input, a “noop” command is sent up the response chain. By default this triggers a beep when it falls off the response chain. In my solution, the NSTextView subclass catches the noop command and instead throws the original keyDown event down the response chain. Then your NSWindow or other views will get any unused keyDown events as normal.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.