[plt-scheme] Key events within a frame

From: Jean-Guillaume Pyraksos (jeapy at free.fr)
Date: Tue Jun 10 11:56:12 EDT 2003

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...



Posted on the users mailing list.