• 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: WM_KEYDOWN
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: WM_KEYDOWN


  • Subject: Re: WM_KEYDOWN
  • From: Andy Lee <email@hidden>
  • Date: Wed, 11 Apr 2007 17:51:47 -0400

On Apr 11, 2007, at 4:14 PM, Michael Novak wrote:
After reading all of this, this post is a waste of time. If you think your
idea is so sacred and genius you probably would have figured out this small
detail, especially after so many have plainly pointed it out to you.

I'm inclined to agree, especially after the "Smith" answer. And yet, perversely, I'll chime in with one more suggestion, because I actually think previous answers have been trying *too* hard to be helpful.


Smith, all you're willing to tell us is that you want to intercept a keystroke before it gets to a text field. I won't assume any particular text-related intent -- only that you want to intercept the keystroke and possibly inject some behavior that your user will determine. Fine. Note that my proposed solution won't detect keystrokes that consist only of modifier keys, so if you're writing a shoot-em-up game that needs the Shift key to fire the gun, you'll need a different solution (possibly involving Carbon). But if you're writing a vi clone with configurable key bindings, this should suffice.

Subclass NSApplication and make your subclass the main class of your app, by modifying Info.plist. In your subclass, override -sendEvent: -- this will enable you to intercept *all* events coming into the application. In the override, check whether the event is a key down event. If so, check whether the text field in question has focus, by seeing if the current first responder is a field editor attached to the text field. If so, do your special stuff. If you want the special stuff to replace the default keystroke behavior, exit - sendEvent: -- otherwise, call [super sendEvent:].

Your NSFormatter approach is not the solution to the problem you posed, because the information you get may not tell you what the keystroke was. For example, if the keystroke was Command-V (for Paste), you won't be able to tell from the NSFormatter. Indeed, there may not have *been* a keystroke, because the user may have selected Paste from the Edit menu.

If any of the above terms are unfamiliar to you (like "first responder" or "field editor"), you can search for them in Xcode's Documentation window, under the Help menu. In any case you'll probably need the docs for NSApplication and NSEvent.

You're welcome.

--Andy (not Smith)

-----Original Message-----
From: cocoa-dev-bounces+mnovak=email@hidden
[mailto:cocoa-dev-bounces+mnovak=email@hidden] On Behalf Of
xcocoa
Sent: Wednesday, April 11, 2007 3:57 PM
Cc: email@hidden
Subject: Re: WM_KEYDOWN


 So you're trying to implement a programming language on the Mac?
Which one? Give us some hints as to the high-level thing you're
trying to achieve.

Its already implemented. We are on pre-release status.

Sorry we can't provide more details. We will submit a demo version to
Apple software once its at RC stage.

regards,
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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


References: 
 >RE: WM_KEYDOWN (From: "Michael Novak" <email@hidden>)

  • Prev by Date: Problem with AESend()
  • Next by Date: NSOutlineView problem
  • Previous by thread: RE: WM_KEYDOWN
  • Next by thread: Re: WM_KEYDOWN
  • Index(es):
    • Date
    • Thread