[plt-scheme] Key events within a frame
Jean-Guillaume Pyraksos wrote:
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> In order to program a game, i want to listen to keyboard events within
> a frame. But i must click in the frame to get the focus. I tried some
> function (whose name i don't remember) to get that focus but it didn't
> work. How can i avoid the click so that the frame can directly get the
> keyboard ? Thanks.
>
> (define my-frame
> (instantiate frame% () (label "Key event")))
>
> (define my-canvas%
> (class canvas%
> (override on-char)
> (define on-char
> (lambda (event)
> (printf "~a~n" (send event get-key-code ))))
> (super-instantiate ())))
>
> (define my-canvas
> (instantiate my-canvas% () (parent my-frame) (min-width 200)
> (min-height 100)))
>
> (send my-frame show #t) ; CLICK IN THE FRAME :-( THEN enter some
> keys...
>
>
(send my-canvas focus) should work.
Katsmall T. Wise, Esquire.