Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / September 2007



Tip: Looking for answers? Try searching our database.

Seems simple enough, but the docs say I shouldn't...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Don Bruder - 28 Sep 2007 16:42 GMT
The scenario:
My application has a window open. The app/window needs to know about
keys being hit - It's not using them as data, storing them, etc - the
keys are controlling program behavior, so it's not actually "text
input". There is no dialog/control active, no special handling required,
it doesn't need unicode, and has no interest in modifiers. It just needs
a Carbon Event based equivalent of this Pre-MacOS X style routine:

WaitNextEvent(keyDownMask|autoKeyMask, &EventGotten, etc...);
if (EventGotten == KeyDownEvent)
  {
     // inspect the key that was hit. If it's one we're interested
     // in, eat it and do something in response to it.
  }

But without the "sins" involved in using WaitNextEvent().

After digging around in the docs, my first instinct is to install a
handler on the window to catch kEventClassKeyboard/kEventRawKeyDown
events and go from there, but according to those same docs, this is a
"Bad Thing(TM)" to do, and the suggestion is to go through the TSM to
get it instead.

I don't want the TSM. I don't need the TSM. I simply want the key the
user pressed, with as little hassle and overhead as possible. If it's
not one of the keys I'm looking for, I'm perfectly willing to (and in
fact, have already coded to do so) CallNextEventHandler() and let
"somebody else" deal with it. If it IS a key I'm looking for, I have
every intention of eating it and ending the handling of the event that
generates it in my handler through the usual "return noErr" method.

So, with that in mind, is it still a "Bad Thing(TM)" to grab the
RawKeyDown event?

Or is there actually some pressing reason for me to go through the TSM?

(And if so, why does Apple provide the RawKeyDown event in the first
place?!?!? It seems like this event would be ideal for what I need to
do, but the "you shouldn't do this" warning leaves me wondering)

Signature

Don Bruder - dakidd@sonic.net - If your "From:" address isn't on my whitelist,
or the subject of the message doesn't contain the exact text "PopperAndShadow"
somewhere, any message sent to this address will go in the garbage without my
ever knowing it arrived. Sorry... <http://www.sonic.net/~dakidd> for more info

Gregory Weston - 28 Sep 2007 17:55 GMT
> The scenario:
> My application has a window open. The app/window needs to know about
[quoted text clipped - 35 lines]
> place?!?!? It seems like this event would be ideal for what I need to
> do, but the "you shouldn't do this" warning leaves me wondering)

For years, Microsoft's marketing of Windows NT boiled down to "if you
have to ask us why you in particular should use it, you in particular
shouldn't use it."

I'd suggest kEventRawKeyDown exists because there _are_ situations in
which it's reasonable or even optimal to use. The documentation probably
doesn't mean "never ever ever do this" so much as "make a serious effort
to see if there's a better way first." Because Apple knows as well as
any of us here that sometimes people get so fixated on implementing a
predetermined solution that they don't notice there's another solution
that takes half as many steps and is more robust.
Don Bruder - 29 Sep 2007 00:17 GMT
> > The scenario:
> > My application has a window open. The app/window needs to know about
[quoted text clipped - 39 lines]
> have to ask us why you in particular should use it, you in particular
> shouldn't use it."

Erm... And this applies to my question in what way?

> I'd suggest kEventRawKeyDown exists because there _are_ situations in
> which it's reasonable or even optimal to use. The documentation probably
[quoted text clipped - 3 lines]
> predetermined solution that they don't notice there's another solution
> that takes half as many steps and is more robust.

Well, since it appears, based on my reading of the docs, that grabbing
the raw key will do the job for me without needing to deal with any of
the TSM stuff (which I simply don't need) and from what I can see from
preliminary tinkering, causes no problems, I'll read that sermon to mean
"If it's going to work for you, go for it."

Thanks. I guess...

Signature

Don Bruder - dakidd@sonic.net - If your "From:" address isn't on my whitelist,
or the subject of the message doesn't contain the exact text "PopperAndShadow"
somewhere, any message sent to this address will go in the garbage without my
ever knowing it arrived. Sorry... <http://www.sonic.net/~dakidd> for more info

Gregory Weston - 29 Sep 2007 13:01 GMT
> > > (And if so, why does Apple provide the RawKeyDown event in the first
> > > place?!?!? It seems like this event would be ideal for what I need to
[quoted text clipped - 5 lines]
>
> Erm... And this applies to my question in what way?

You can be warned off of using a solution in the general case but still
have it be appropriate for specific situations.

> > I'd suggest kEventRawKeyDown exists because there _are_ situations in
> > which it's reasonable or even optimal to use. The documentation probably
[quoted text clipped - 11 lines]
>
> Thanks. I guess...
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.