[plt-scheme] How is caps lock supposed to be handled in keymaps?
Hi everyone,
I'm attacking a very nasty bug in DivaScheme involving caps lock. Given a
keymap%, I bind my own custom functions by using ADD-FUNCTION. However,
it appears that when Caps Lock is on, the associated keys aren't found.
I've been able to work around the issue by intercepting key-event%s that
look like they've been affected by caps lock, and transforming them so
that they don't:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; A grab-key-function that looks at unmapped keys that look like
;; capslock is on, and tries to remap to keys that aren't caps-locked.
(define (ignores-caps-lock-grab-key-function str km editor event)
(define (caps-lock-on?)
(and (not str)
(is-a? event key-event%)
(char? (send event get-key-code))
(char-upper-case? (send event get-key-code))
(not (send event get-shift-down))))
(define (copy-key/downcase)
(let ([key-event
(new key-event%
[key-code (char-downcase (send event get-key-code))]
[shift-down #f]
[control-down (send event get-control-down)]
[meta-down (send event get-meta-down)]
[alt-down (send event get-alt-down)]
[x (send event get-x)]
[y (send event get-y)]
[time-stamp (send event get-time-stamp)])])
(send key-event set-other-altgr-key-code
(send key-event get-other-altgr-key-code))
(send key-event set-other-shift-altgr-key-code
(send key-event get-other-shift-altgr-key-code))
(send key-event set-other-shift-key-code
(send key-event get-other-shift-key-code))
key-event))
(if (caps-lock-on?)
(send km handle-key-event editor
(copy-key/downcase))
#f))
;; later on in the code:
(send command-keymap set-grab-key-function
ignores-caps-lock-grab-key-function)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
I've been reading the documentation in MrEd, but there's nothing in there
about Caps Lock, so I have no idea if what I'm doing here is actually
correct. *grin*
Is what I'm doing the right thing to do, and if so, can the situation
involving Caps Lock be better documented in the MrEd docs? Thanks!