[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
          scheme/gui
          framework/framework)

(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)
   editor-canvas)


(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")
   (cond
     [(not callback-name/false)
      (let ([meta-down? (send event get-meta-down)]
            [control-down? (send event get-control-down)])
        (cond
          [(or meta-down? control-down?)
           no-further-dispatch-needed]
          [else
           more-dispatch-needed]))]
     [else
      no-further-dispatch-needed]))



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