Receiving keyboard events

Lex Spoon lex at cc.gatech.edu
Thu Aug 2 03:45:37 UTC 2001


Frantisek Fuka <fuxoft at terminal.cz> 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...
> 
> 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.....
> 

Ah, I didn't know you could ever get automatic keyboard events.  Are you
sure you didn't implement a mouseEnter: as well, while you were
sleepwalking or something?  :)  Anyway, you can explicitly grab the
focus with code like this:

	someHand newKeyboardFocus: myMorph

(One way to access a hand is "World currentHand".)  I haven't tested it,
but this ought to work regardless of where the mouse is.  Just be aware
that as the mouse moves around, any other morph might grab the focus
back -- there is only one morph at a time with keyboard focus.


By the way, I've written a short tutorial on morphic basics in the
"Learning Morphic" project on Bob's Superswiki.  It's not detailed, but
it gets you through the basic steps.  Actually, I'm not sure that
*detailed* is very useful, anyway, because once you have the general
ideas, you can look directly in the code.  In there, I give about a
5-step process for getting keyboard events, because I wasn't aware of a
way to get them directly.

More generally, check out the "Morphic" page on the Swiki if you haven't
already.  I cleaned it up a bit recently, and it should be more
approachable now.


Lex




More information about the Squeak-dev mailing list