[plt-scheme] making a keymap that overrides the Mac OS X menubar?

From: Danny Yoo (dyoo at cs.wpi.edu)
Date: Mon Mar 17 01:08:25 EDT 2008

Hi everyone,

I'm trying to figure out how to make a keymap that takes precedence even 
over the items in a menu%.  I have the following test program that tries 
to throw away any keystrokes that have control or metas on them:

#lang scheme/base
(require scheme/class

(define (make-simple-editor frame)
   (define insert-keymap (new keymap:aug-keymap%))
   (define editor (new text%))
   (define editor-canvas (new editor-canvas%
                              [parent (send frame get-area-container)]
                              [editor editor]))
   (send insert-keymap set-grab-key-function rigid-grab-key)
   (send (send editor get-keymap) chain-to-keymap insert-keymap #t)

(define (rigid-grab-key callback-name/false km editor event)
   (define no-further-dispatch-needed #t)
   (define more-dispatch-needed #f)
   (printf "rigid-grab-key fired~n")
     [(not callback-name/false)
      (let ([meta-down? (send event get-meta-down)]
            [control-down? (send event get-control-down)])
          [(or meta-down? control-down?)

(define (test)
   (define frame (new (frame:basic-mixin frame%)
                      [label "testing"]
                      [width 200]
                      [height 200]))
   (make-simple-editor frame)
   (send frame show #t))

However, under Mac OS X, if the use presses a key that's bound by a menu%
item, like the Preferences keybinding "Cmd-," or the minimize keystroke 
"Cmd-M", then the menu item fires off instead of my grab-key.

Does anyone have suggestions on intercepting such key events?  I'm not 
sure if this problem is exclusive to Mac OS X, but I suspect that the same 
issue would come up in Windows too.

Thanks for any help!

Posted on the users mailing list.