• 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
Re: NSTextField not consuming keyDown events; How do I prevent super view from receiving those events?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTextField not consuming keyDown events; How do I prevent super view from receiving those events?


  • Subject: Re: NSTextField not consuming keyDown events; How do I prevent super view from receiving those events?
  • From: Eric Wing <email@hidden>
  • Date: Tue, 13 Mar 2012 17:00:22 -0700

On 3/13/12, email@hidden <email@hidden> wrote:
>
> On 13 Mar 2012, at 22:50, Eric Wing wrote:
>
>> I have a very simple custom view where I override keyDown: and keyUp:.
>>
>>
>> Is there a way to get the text field (and any other widgets that might
>> do this like NSTextView) to consume the events they process so my
>> custom view doesn't receive them?
>
> Are you sure you aren't accidentally passing the event on up the responder
> chain?
>
> - (void)keyDown:(NSEvent *)theEvent {
>
>     // consume event
>     if ([theEvent modifierFlags] & NSNumericPadKeyMask) {
>         [self processtEvent:theEvent];
>     }
>
>     // pass on up the responder chain
>     [super keyDown:theEvent];
>
> }
>
>
> Regards
>
> Jonathan Mitchell
> Mugginsoft LLP
>

I am not calling [super keyDown:event] in my custom subclass. But the
problem is that it is the NSTextField that is passing the event to my
class, not the other way around. I did not subclass NSTextField (nor
do I really want to).

So I found a few solutions, but I'm hoping for something a little
better, or perhaps assurance that this is a legitimate solution and I
won't totally break things in some other way. (I'm wondering what the
use case is for NSTextField not consuming the events.)

- Put the text field inside another custom view that consumes the
events before it reaches my real custom view.

- Create a new responder that eats events and set the nextResponder of
the NSTextField to this responder object.

- Track the becomesFirstResponder and resignFirstResponder in my
custom view and disregard all events that come it when it is NOT the
firstResponder.


An aside, I'm wondering if this NSTextField not consuming key events
is a potentional security risk. For fun, I tried using an
NSSecureTextField the same way and my custom view is receiving the
echo of all the key strokes. I know Apple does things to fortify
NSSecureTextField from external examination for security. However, I
wonder if some kind of injection attack could be made on the superview
hosting the text field. Simply doing the equivalent of setting a
category on the super view for keyDown and inspecting the results. (I
don't really know what I'm talking about so don't take me too
seriously. I have no idea how to attack an app. It's just an
observation.)

Thanks,
Eric
--
Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/
_______________________________________________

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: NSTextField not consuming keyDown events; How do I prevent super view from receiving those events?
      • From: "email@hidden" <email@hidden>
References: 
 >NSTextField not consuming keyDown events; How do I prevent super view from receiving those events? (From: Eric Wing <email@hidden>)
 >Re: NSTextField not consuming keyDown events; How do I prevent super view from receiving those events? (From: "email@hidden" <email@hidden>)

  • Prev by Date: Re: [Q] Why is the threading and UI updating designed to be done only on a main thread?
  • Next by Date: Re: NSDrawTiledRects Only Draws One Side
  • Previous by thread: Re: NSTextField not consuming keyDown events; How do I prevent super view from receiving those events?
  • Next by thread: Re: NSTextField not consuming keyDown events; How do I prevent super view from receiving those events?
  • Index(es):
    • Date
    • Thread