[Newbies] Capture keyboard focus for real and true.

Blake blake at kingdomrpg.com
Mon Jul 2 23:23:18 UTC 2007

On Mon, 02 Jul 2007 16:06:08 -0700, Bert Freudenberg  
<bert at freudenbergs.de> wrote:

> Send #addKeyboardListener: with your morph as argument to the Hand. This  
> way you get all keyboard events independent ot keyboard focus.

Well, that's what I thought. In the words of Randy Newman, maybe I'm doing  
it wrong. In my morph class I have:

    super initialize.
    xDir _ 0.
    yDir _ 0.
    ActiveHand addKeyboardListener: self; keyboardFocus: self.

which is the only reason it works at all. In my keydown method, I have:

keyDown: evt
    self halt.
    (evt keyCharacter = $W) ifTrue: [xDir _ 0. yDir _ -1].
    (evt keyCharacter = $S) ifTrue: [xDir _ 0. yDir _ 1].
    (evt keyCharacter = $D) ifTrue: [xDir _ 1. yDir _ 0].
    (evt keyCharacter = $A) ifTrue: [xDir _ -1. yDir _ 0].

I put in the halt just in case the code was wrong somehow, but if I click  
on any text window, messages stop going to keyDown for my morph.


More information about the Beginners mailing list