[Cuis-dev] keyboard events in custom morph

ken.dickey at whidbey.com ken.dickey at whidbey.com
Thu Aug 1 14:23:36 PDT 2024


On 2024-08-01 13:44, Mark Volkmann via Cuis-dev wrote:

> I'm able to get mouse events in a custom morph, but I haven't been able 
> to do the same for keyboard events. Here is what I tried:
> 
> I created a subclass of PlacedMorph.
> 
> In the initialize method I have this:
> 
> initialize
> super initialize.
> self setProperty: #handlesKeyboard toValue: true.
> 
> In the keyDown: method I have this:
> 
> keyDown: aKeyboardEvent
> 'got keyDown' print.
> 
> I create an instance of my custom morph in a Workspace and send it 
> #openInWorld to render it.
> I then move the mouse over it and press a key, but I don't see output 
> in the Transcript.
> Does anyone see what I'm missing?

Yes.  You are forgetting to ask for #handlesKeyboard iMplementors.

Morph>>processKeystroke: shows you need to supply a handler to 
#'keyStroke:'

Cuis Smalltalk knows a lot about itself.  You need to practice various 
ways of asking the system about itself.

Might be a good chapter in your blog..

HTH,
-KenD


More information about the Cuis-dev mailing list