[racket] Capturing key events at the top level

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Thu May 9 20:23:21 EDT 2013

I noticed that when I printed out the result of (send mw has-focus?)
on every printf, it is always #f despite having been called with (send
mw focus)

On Thu, May 9, 2013 at 6:05 PM, Jay McCarthy <jay.mccarthy at gmail.com> wrote:
> In the program below, I never receive on-subwindow-char calls (or any
> of the other calls). (Except when they correspond to mouse events like
> the wheel up events.) Is there some other way that I'm supposed to get
> key events from a top level window? I know I can create a canvas, but
> I'd like to get all the key events.
>
> Jay
>
> #lang racket/gui
> (define key-frame%
>   (class* frame% ()
>     (define/override (on-traverse-char e)
>       (printf "on-traverse-char Got ~v\n" e)
>       #t)
>     (define/override (on-menu-char e)
>       (printf "on-menu-char Got ~v\n" e)
>       #t)
>     (define/override (on-subwindow-char r e)
>       (printf "on-subwindow-char Got ~v\n" (send e get-key-code))
>       #t)
>     (define/override (on-subwindow-event r e)
>       (printf "on-subwindow-event Got ~v\n" e)
>       #t)
>     (define/override (on-subwindow-focus r e)
>       (printf "on-subwindow-focus Got ~v\n" e)
>       #t)
>     (define/override (on-superwindow-enable on?)
>       (printf "on-superwindow-enable Got ~v\n" on?)
>       #t)
>     (define/override (on-superwindow-show on?)
>       (printf "on-superwindow-show Got ~v\n" on?)
>       #t)
>     (define/override (on-focus on?)
>       (printf "on-focus Got ~v\n" on?)
>       #t)
>     (define/override (on-activate on?)
>       (printf "on-activate Got ~v\n" on?)
>       #t)
>
>     (super-new)))
>
> (define mw (new key-frame% [label "key-frame"]))
> (send mw focus)
> (send mw create-status-line)
> (define label-m
>   (new message% [parent mw]
>        [label "Message"]))
> (send mw show #t)
>
> --
> Jay McCarthy <jay at cs.byu.edu>
> Assistant Professor / Brigham Young University
> http://faculty.cs.byu.edu/~jay
>
> "The glory of God is Intelligence" - D&C 93



-- 
Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University
http://faculty.cs.byu.edu/~jay

"The glory of God is Intelligence" - D&C 93

Posted on the users mailing list.