[plt-scheme] trapping key events in text-field%

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sat Nov 29 16:01:04 EST 2008

At Sat, 29 Nov 2008 11:53:04 -0800, "Gregory Cooper" wrote:
> What's the right way to catch key events in a text-field%?  I thought
> I should override its on-subwindow-char, but that seems to catch each
> event twice.  E.g., if I run the following program and type "a" into
> the text field, it displays:
> 
> 1: a
> 2: a
> 3: release
> 4: release
> 
> If I remove the (super ...) call, I get:
> 
> 1: a
> 2: release
> 
> but then the "a" doesn't appear in the text field.

The duplicate events are a problem with `text-field%'. Internally, a
`text-field%' is composed of multiple windows, and its
`on-subwindow-char' method is getting called once for each internal
window. I'll work on that. Meanwhile, as a workaround, you could ignore
an event that's `eq?' to the previously received event.

If you remove the `super' call, then your implementation is returning a
true value, which indicates that the event shouldn't be propagated any
further. That's why you only get one copy of the event when you remove
the `super' call (which is returning #f) and why the event doesn't get
delivered and handled in the usual way.


Matthew



Posted on the users mailing list.