[squeak-dev] How do I create a "synthetic" keyboard event?

karl ramberg karlramberg at gmail.com
Sun Feb 19 09:18:29 UTC 2023


Hi,
General events are a little tricky to set up and generate like you describe.

But there are tools to help you.

You can load these two fixes and use EventRecordingSpace.
http://source.squeak.org/inbox/EToys-kfr.493.mcz
http://source.squeak.org/inbox/EToys-kfr.494.mcz

EventRecordingSpace open

You can record all events inside for later playback and editing saving etc.

Best,
Karl

On Sun, Feb 19, 2023 at 4:43 AM Eduardo Ochs <eduardoochs at gmail.com> wrote:

> Hi list,
>
> this is a follow-up to these two messages:
>
>
> http://lists.squeakfoundation.org/pipermail/squeak-dev/2023-February/223407.html
>
> http://lists.squeakfoundation.org/pipermail/squeak-dev/2023-February/223408.html
>
> The first one was a question that I asked, and the second was an
> answer by Marcel Taeumel. I was able to decypher almost all his
> pointers - but not yet this one:
>
>   HandMorph >> #generateKeyboardEvent:
>
> I am using this code:
>
>   a := Array with: 50 at 100 with: 200 at 300 with: 100 at 400.
>   b := (PolygonMorph
>           vertices: a color: Color red
>           borderWidth: 1 borderColor: Color black).
>   World addMorph: b.
>
>   b beSmoothCurve.
>   b beStraightSegments.
>
>   b vertices.
>   b vertices at: 1.
>   b vertices at: 1 put: 40 at 100.
>   b vertices at: 1 put: 50 at 100.
>   b vertices at: 1 put: 40 at 100. b computeBounds.
>   b vertices at: 1 put: 50 at 100. b computeBounds.
>
>   b color.
>   b color: Color banana.
>   b color: Color red.
>
>   e := EventHandler new.
>   b eventHandler.
>   b eventHandler: nil.
>   b eventHandler: e.
>
>   bl := [ :a :b | { a . b }].
>   bl := [ :a :b | Transcript show: { a . b }; cr. ].
>   bl numArgs.
>   bl value: 2 value: 3.
>   bl perform: #value:value: with: 2 with: 3.
>
>   bl := [ :evt :sm | Transcript show: { evt . sm }; cr. ].
>   bl := [ :evt :sm | Transcript show: { evt keyValue . sm }; cr. ].
>   bl := [ :evt :sm | self halt. ].
>   e on: #keyStroke send: #value:value: to: bl.
>   b currentHand newKeyboardFocus: b.
>
> It is meant to be used in a workspace. By selecting the right parts of
> it and running them with "do it"s or "print it"s in the right order I
> can create a PolygonMorph, some EventHandlers, and some blocks, and
> then I can make the PolygonMorph react to keyboard events in different
> ways. The last line switches the keyboardFocus to my PolygonMorph, and
> then I can send several keystroke events to my PolygonMorph, and
> inspect their events either on the transcript or on the debugger.
>
> Question: suppose that evt is an event whose printed representation is
> this one:
>
>   [79 at 273 keystroke ' ' (32) 956759]
>
> I know that this means that:
>
>   evt position -> 79 at 273
>   evt type -> #keystroke
>   evt keyValue -> 32
>   evt keyCode -> 32
>   evt source -> self currentHand
>   evt timeStamp -> 956759
>
> How do I write code that creates an event like that? I would like to
> create, ahem, "synthetic keystrokes", and experiment with sending them
> to certain morphs...
>
>   Thanks in advance!
>     Eduardo Ochs
>     http://anggtwu.net/eev-squeak.html
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20230219/590b8555/attachment.html>


More information about the Squeak-dev mailing list