[racket] Capturing key events at the top level

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

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.


#lang racket/gui
(define key-frame%
  (class* frame% ()
    (define/override (on-traverse-char e)
      (printf "on-traverse-char Got ~v\n" e)
    (define/override (on-menu-char e)
      (printf "on-menu-char Got ~v\n" e)
    (define/override (on-subwindow-char r e)
      (printf "on-subwindow-char Got ~v\n" (send e get-key-code))
    (define/override (on-subwindow-event r e)
      (printf "on-subwindow-event Got ~v\n" e)
    (define/override (on-subwindow-focus r e)
      (printf "on-subwindow-focus Got ~v\n" e)
    (define/override (on-superwindow-enable on?)
      (printf "on-superwindow-enable Got ~v\n" on?)
    (define/override (on-superwindow-show on?)
      (printf "on-superwindow-show Got ~v\n" on?)
    (define/override (on-focus on?)
      (printf "on-focus Got ~v\n" on?)
    (define/override (on-activate on?)
      (printf "on-activate Got ~v\n" on?)


(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

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

Posted on the users mailing list.