• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
becomeFirstResponder and keyDown
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

becomeFirstResponder and keyDown


  • Subject: becomeFirstResponder and keyDown
  • From: "gMail.com" <email@hidden>
  • Date: Wed, 21 Oct 2009 18:17:33 +0200
  • Thread-topic: becomeFirstResponder and keyDown

Hi,
I would like to detect whether the 'e' key is pressed every time I click on
an NSView. If the view is already the firstResponder, I can quite memorize
that key pressed when keyDown and reuse it when mouseDown. Then I erase it
when keyUp.
But if the user presses the 'e' key when the firstResponder is on another
view, then he clicks on my view, I cannot detect that the 'e' is still
pressed. I have been trying to detect the key already pressed subclassing
becomeFirstResponder but I get nothing. Any idea?

- (BOOL)becomeFirstResponder
{
    unsigned int    eventMask = NSKeyDownMask;
    NSEvent          *theEvent = [[self window]
                        nextEventMatchingMask:eventMask untilDate:nil
                        inMode:NSEventTrackingRunLoopMode dequeue:YES];

    NSEventType        eventType = [theEvent type];
    if(eventType == NSKeyDown){
        mCharCurrentlyPressed = [[theEvent charactersIgnoringModifiers]
                                               characterAtIndex:0];
        NSLog(@"becomeFirstResponder %c", mCharCurrentlyPressed );
    }

    return YES;
}


Best Regards
--
LL


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: becomeFirstResponder and keyDown
      • From: Quincey Morris <email@hidden>
  • Prev by Date: Re: GC Re: Questions about Nib Object Retention
  • Next by Date: Sending a Selector to another Class.
  • Previous by thread: iPhone: View with "layer" type fading?
  • Next by thread: Re: becomeFirstResponder and keyDown
  • Index(es):
    • Date
    • Thread