[comp.sys.mac.programmer] why don't i get any "keyUp" events?

fleabag@athena.mit.edu (jeff bellsey) (10/06/90)

well, i wrote this simple utility which dumped all events
into a window to see why i wasn't getting any keyUp events
in my program. this program didn't get them either.

what could i be doing wrong?  could it be the keyboard? my
spelling? the humidity!? 

btw, "gimme a break, man, i'm just starting out!" applies here.

thanks *muchly* for any help!

:jeff
fleabag@athena.mit.edu

andyp@treehouse.UUCP (Andy Peterman) (10/06/90)

In article <1990Oct6.034350.23107@athena.mit.edu> fleabag@athena.mit.edu (jeff bellsey) writes:
>well, i wrote this simple utility which dumped all events
>into a window to see why i wasn't getting any keyUp events
>in my program. this program didn't get them either.
>
>what could i be doing wrong?  could it be the keyboard? my
>spelling? the humidity!? 

I encountered this same problem about a year ago.  It turns out that the
OS EventManager normally blocks keyUp events.  Use SetEventMask to enable 
it.  See IM-II page 70 for details.

	Andy Peterman
	treehouse!andyp@gvgpsa.gvg.tek.com

deadman@garnet.berkeley.edu (Ben Haller) (10/06/90)

In message <1990Oct6.034350.23107@athena.mit.edu>, fleabag@athena.mit.edu
(jeff bellsey) says:

> well, i wrote this simple utility which dumped all events
> into a window to see why i wasn't getting any keyUp events
> in my program. this program didn't get them either.
> what could i be doing wrong?  could it be the keyboard? my
> spelling? the humidity!?
> 
> btw, "gimme a break, man, i'm just starting out!" applies here.
>
> thanks *muchly* for any help!
>
> :jeff
> fleabag@athena.mit.edu

The problem is quite simple.  In Inside Macintosh Vol. II, chapter 3
(Operating System Event Manager), on page II-70, is the routine
SetEventMask.  Excerpt:

   SetEventMask sets the system event mask to the specified event mask.
 The Operating System Event Manager will post only those event types
 that correspond to bits set in the mask...The system event mask is
 initially set to post all except key-up events.

  So what you need to do is just call SetEventMask with everyEvent (-1),
and that should solve your problem.  I *think* on old versions of the
system software the event mask wasn't set back when an application quit, so
you should set it on exit to everyEvent-keyDownMask or whatever (now I'm
just going from memory, so the names may be wrong).
  I have a harder question.  What the hell is the system event mask
*useful* for??  Why does it exist?  Why don't all applications get all
events, and leave it at that?  I mean, all it means is you have to have a
default case in your switch statement in your event loop, and you pretty
much always do anyway.  Did Apple really think that programmers wouldn't
know how to handle it if they received keyUp events?  Or is there a more
sane reason?
  I know the first time I wanted to get keyUp events it confused the hell
out of me...bet it does to 90% of Mac programmers.
  Oh well.  Apple is so easy to make fun of...

-Ben Haller (deadman@garnet.berkeley.edu)
"The gang and the government, no different..." -  Jane's Addiction

Greg@AppleLink.apple.com (Greg Marriott) (10/08/90)

In article <1990Oct6.075532.22574@agate.berkeley.edu> 
deadman@garnet.berkeley.edu (Ben Haller) writes:
>   I have a harder question.  What the hell is the system event mask
> *useful* for??  Why does it exist?  Why don't all applications get all
> events, and leave it at that?  I mean, all it means is you have to have a
> default case in your switch statement in your event loop, and you pretty
> much always do anyway.  Did Apple really think that programmers wouldn't
> know how to handle it if they received keyUp events?  Or is there a more
> sane reason?

Since the event queue is limited in size, you don't want unneeded events 
pushing more important ones off the front of the queue.  Most apps just 
care about which key was pressed, not when the user let go of it.  Imagine 
just having key events (for a moment)... including key up events would cut 
the amount of "type-ahead" in half.  Since most apps will ignore key
up events, the default is to mask them out.

Greg Marriott
Just Some Guy
Apple Computer, Inc.