Receiving keyboard events

Jesse Welton jwelton at pacific.mps.ohio-state.edu
Wed Aug 1 13:57:59 UTC 2001


Frantisek Fuka wrote:
> 
> How can my morph receive keyboard events even when the mouse pointer is 
> not hovering above this morph? I defined handlesKeyboard: ^true and now 
> keyStroke: gets invoked only when the mouse pointer is over my morph...

I think the problem is probably that your morph isn't requesting the
keyboard focus.  If you request the keyboard focus on mouseEnter or
mouseDown (see, eg, PluggableTextMorph>>mouseEnter and
TextMorph>>mouseDown:), and don't let go of it on mouseLeave (see
PluggableTextMorph>>mouseLeave), you should be happier with the
results.

> Anyyway, is ther some detailed documentation about this stuff? There is 
> almost nothing in the sources and I tried browsing the swiki but found 
> nothing about input events.....

I don't think there is any good documentation of Morphic event
handling, and it is tricky to trace it out in the source because the
logic can be somewhat convoluted.  It really helps to be able to trace
it forward and backward using 'implementors of' and 'senders of'; and
look especially at HandMorph, in this case the 'event handling' and
'focus handling' categories.

Ignore the following if it pushes you to overload.

It took me a little while to figure out why, without asking for the
focus, you would be able to receive keyboard events at all.  Tracing
forward from HandMorph>>HandleEvent: and sendKeyboardEvent:, one finds
that if the hand does not have any focus, it sends processEvent: to
its owner.  This trickles down to
MorphicEventDispatcher>>dispatchDefault:with:, which dispatches the
event to the topmost submorph of the world containing the event's
position.

So an alternative for the future might be to make an
application-specific PasteUpMorph (ie, world) subclass which sends all
unfocused events to your primary morph of interest.  But that's
probably crazy; it's probably better just to make sure you always have
a sensible focus set.

-Jesse




More information about the Squeak-dev mailing list